SpringBoot学习-支持thymeleaf模板引擎
2017-09-19 16:10
483 查看
Springboot默认是不支持JSP的,默认使用thymeleaf模板引擎。配置过程比较简单,引入jar支持就行
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>application.properties文件配置一些信息(非必须)
#thymelea模板配置
spring.thymeleaf.prefix=classpath:/templates/
spring.thymeleaf.cache=false
spring.thymeleaf.suffix=.html
spring.thymeleaf.mode=HTML5
spring.thymeleaf.encoding=UTF-8
spring.thymeleaf.content-type=text/html基本上就可以了,现在写个controller测试一下
@Controller
public class Test2Controller {
@RequestMapping("to")
public String to(){
return "hello";
}
@RequestMapping("test")
public String test(){
return "test";
}
}注意一点,controller的注解是@Controller,而不是@RestController,区别在项目搭建的时候说过
在templates目录下新建几个页面,SpringBoot有个默认首页的设置,可以把index.html放在static静态资源目录下,就可以直接访问了
注意:HTML中引用Js和CSS的文件需要也放在static目录下才能被正确访问
测试结果:
有一个小问题:
IDEA创建的HTML文件默认的meta标签内是没有收尾的,会引起报错,我们加上收尾的“/”就行.
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>application.properties文件配置一些信息(非必须)
#thymelea模板配置
spring.thymeleaf.prefix=classpath:/templates/
spring.thymeleaf.cache=false
spring.thymeleaf.suffix=.html
spring.thymeleaf.mode=HTML5
spring.thymeleaf.encoding=UTF-8
spring.thymeleaf.content-type=text/html基本上就可以了,现在写个controller测试一下
@Controller
public class Test2Controller {
@RequestMapping("to")
public String to(){
return "hello";
}
@RequestMapping("test")
public String test(){
return "test";
}
}注意一点,controller的注解是@Controller,而不是@RestController,区别在项目搭建的时候说过
在templates目录下新建几个页面,SpringBoot有个默认首页的设置,可以把index.html放在static静态资源目录下,就可以直接访问了
注意:HTML中引用Js和CSS的文件需要也放在static目录下才能被正确访问
测试结果:
有一个小问题:
IDEA创建的HTML文件默认的meta标签内是没有收尾的,会引起报错,我们加上收尾的“/”就行.
相关文章推荐
- springboot学习:spring-boot中如何使用thymeleaf模板引擎
- SpringBoot的Thymeleaf支持,结合SpringMVC做的案例(学习SpringBoot实战)
- SpringBoot学习-支持JPA
- SpringBoot学习:添加JSP支持
- spring boot 学习(二)spring boot 框架整合 thymeleaf
- 深入学习spring-boot系列(三)--使用thymeleaf模板
- Spring Boot学习之旅:(十二)模版引擎-Thymeleaf
- springBoot(5):web开发-模板引擎FreeMarker与thymeleaf
- SpringBoot学习-支持Jersey
- Spring Boot 学习笔记 4 : Thymeleaf
- 深入学习spring-boot系列(三)--使用thymeleaf模板
- 详解spring Boot 集成 Thymeleaf模板引擎实例
- 深入学习spring-boot系列(三)--使用thymeleaf模板
- springboot webmvc thymeleaf 模板引擎
- 深入学习spring-boot系列(三)--使用thymeleaf模板
- SpringBoot入门:新一代Java模板引擎Thymeleaf(实践)
- SpringBoot学习-支持PageHelp插件使用
- springboot学习(4)springboot使用thymeleaf完成数据的页面展示
- 深入学习spring-boot系列(三)--使用thymeleaf模板
- BabyLog SpringBoot+MyBatis+Thymeleaf+Amaze UI 整合学习