1.构建一个新的SpringBoot项目,选择依赖为Thymeleaf和web
工具:idea 2019.1
gradle: 5.2.1
SpringBoot 2.1.4
2. 查看引入的依赖正常,查看项目结构
在src文件夹下,除了application.properties文件之外还有两个文件夹 static和templates。static一般用于存放静态资源文件,比如.css文件,.js文件,img文件等,templates文件夹用于存放模板文件,也就是HTML文件等的。application.properties必须存放在src的根目录下面。
3. 在application.properties文件中,写入Thymeleaf的属性
#可以选择换一个端口号启动
server.port=9000
#设置编码为UTF-8
spring.thymeleaf.encoding=UTF-8
#设置支持HTML,如果写成HTML5的话,这个属性校验比较严格
spring.thymeleaf.mode=LEGACYHTML5
#设置前缀
spring.thymeleaf.prefix=classpath:/templates/
#设置后缀
spring.thymeleaf.suffix=.html
#默认缓存是开启的,我们需要将它关闭
spring.thymeleaf.cache=false