一、基础理论
1、概念
SpringBoot推荐使用Thymeleay来代替jsp进行动态页面展示,和jsp不同,它不需要编译就能运行,所以效率更高。
Thymeleay是基于html的,只要会html,thymeleaf很简单。
2、springboot集成thymeleaf
A.在新建springboot项目时,需要在templates engines中勾选thymeleaf。
这样的话pom文件中就有thymeleaf的起步依赖了。
你也可以不勾选,直接在pom文件中添加thymeleaf的起步依赖。
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
B、在resources的templates目录下新建thymeleaf文件,以.html结尾。
在<html>的头标签中添加:
<html lang="en" xmlns:th="http://www.thymeleaf.org">
这样就可以在html文件在使用thymeleaf的标签了。
C、缓存
thymeleaf是有缓存的,thymeleaf文件修改后,浏览器再次访问,还是原有的未修改的内容。
解决:
在properties文件中:
spring.thymeleaf.cache=false
idea设置:
edit configura