0
点赞
收藏
分享

微信扫一扫

十四、Spring Boot中使用Thymeleaf模板引擎

(一)添加依赖

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>

spring-boot-starter-thymeleaf下面已经包括了spring-boot-starter-web,所以可以把spring-boot-starter-web的依赖去掉。

(二)配置属性
其实完全可以使用不用配置,但是Spring Boot官方文档建议在开发时将缓存关闭,那就在application.properties文件中加入下面这行吧:

spring.thymeleaf.cache=false

(三)添加页面
在​​​resources/templates​​​文件夹下添加​​list.html​​页面

(四)访问页面

@GetMapping("/list")
public String toTemplates(){
return "/list";
}

备注:
  关于Thymeleaf的详细用法以及标签的使用,参见文章​Spring Boot (三):Thymeleaf 的使用


举报

相关推荐

0 条评论