1、导入 Maven 依赖
<!-- SpringBoot 和 ThymeLeaf 整合包 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
2、在 html 文件中,引入 ThymeLeaf 的命名空间
<!DOCTYPE html>
<html lang="zh-CN" xmlns:th="http://www.thymeleaf.org">
<!-- 1、Thymeleaf 几乎可以替换所有的 thml 属性 -->
<!-- 2、命名规则:th:属性名称 -->
<!-- 3、也就是说,src 属性,在 ThymeLeaf 中用 th:src 来替代 -->
<!-- 主体内容 -->
</html>
3、关闭 ThymeLeaf 的缓存
# 在 SpringBoot 的配置文件中书写,该书写方式使用的是 yaml
# 关闭 ThymeLeaf 的缓存,便于调试
spring:
thymeleaf:
cache: false
4、学习途径
官方网站:https://www.thymeleaf.org/
官方文档:https://www.thymeleaf.org/doc/tutorials/3.0/usingthymeleaf.html