十四、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 的使用

猜你喜欢

转载自blog.csdn.net/panchang199266/article/details/82707347