Springboot搭建web项目访问自定义位置的html页面
来源:互联网 发布:网络职业男士头像大全 编辑:程序博客网 时间:2024/06/06 02:18
xml配置文件如下:
<parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>1.5.6.RELEASE</version><relativePath/> <!-- lookup parent from repository --></parent><properties><project.build.sourceEncoding>UTF-8</project.build.sourceEncoding><project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding><java.version>1.8</java.version><velocity.version>1.7</velocity.version></properties><dependencies><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-test</artifactId><scope>test</scope></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-freemarker</artifactId></dependency></dependencies>2、项目截图
3、详解application.properties文件的配置:
#服务启动端口号server.port=8080 #访问根路径,默认情况下IntelliJ IDEA是没有访问根路径的,如localhost:8080/请求路径server.contextPath=/html###FREEMARKER (FreeMarkerAutoConfiguration)spring.freemarker.allow-request-override=falsespring.freemarker.cache=truespring.freemarker.check-template-location=truespring.freemarker.charset=UTF-8spring.freemarker.content-type=text/htmlspring.freemarker.expose-request-attributes=truespring.freemarker.expose-session-attributes=falsespring.freemarker.expose-spring-macro-helpers=false#spring.freemarker.prefix=spring.freemarker.request-context-attribute=rc#spring.freemarker.settings.*=#模板加载后缀spring.freemarker.suffix=.html#模板加载路径spring.freemarker.template-loader-path=classpath:/views/#非templates目录是需要指定模板路径的,thymeleaf默认的前缀是templat
默认情况下,Spring Boot将从类路径或根目录中的
/static
( /public
或/resources
或/META-INF/resources
)目录中提供静态内容ServletContext
。它使用ResourceHttpRequestHandler
从Spring MVC,所以你可以通过添加自己WebMvcConfigurerAdapter
和覆盖该 addResourceHandlers
方法来修改这种行为。4、login.html页面
<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"/> <title>Title</title></head><body> <h1>Login页面</h1></body></html>
5、controller
@Controllerpublic class HtmlController { Logger logger = LoggerFactory.getLogger(HtmlController.class); @RequestMapping(value = "/login", method = RequestMethod.GET) public String login() { logger.info("====="); return "/login"; }}
6、application
@SpringBootApplicationpublic class HtmlApplication {public static void main(String[] args) {SpringApplication.run(HtmlApplication.class, args);}}
启动访问,http://localhost:8080/html/login
阅读全文
0 0
- Springboot搭建web项目访问自定义位置的html页面
- 通过SpringBoot访问HTML页面
- 搭建SpringBoot的web-mvc项目
- SpringBoot项目Web应用搭建
- SpringBoot学习笔记(十一):在STS导入之前的Web项目,发现html页面中文乱码
- IDEA上面搭建一个SpringBoot的web-mvc项目
- IDEA上面搭建一个SpringBoot的web-mvc项目
- IDEA上面搭建一个SpringBoot的web-mvc项目
- SpringBoot项目如何访问jsp页面
- SpringBoot项目如何访问jsp页面
- 使用idea+springboot+Mybatis搭建web项目
- 使用idea+springboot+Mybatis搭建web项目
- IDEA下用springboot搭建web项目
- 自定义Maven SpringBoot Web项目骨架
- web项目web-inf下面的jsp页面不能访问
- 简单的springboot项目搭建
- Web项目自定义错误页面
- SpringBoot访问JSP页面的完整代码
- [LintCode]38.搜索二维矩阵 II
- 使用Spring Boot搭建个人博客全记录
- C++ 容器的概念
- BFC
- HTML&CSS初级
- Springboot搭建web项目访问自定义位置的html页面
- FTP部署
- JavaScript 对象_0
- Spring cloud 学习(二)Feign
- python实现阿拉伯数字和罗马数字的互相转换
- Java微信支付功能整理
- 设计模式之禅笔记-享元模式
- 电子通讯录(1)
- 使用Valgrind Memcheck检查内存