1.首先要导入mvc和thymeleaf的依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
注意:将HTML文件放在resources\templates目录下
2.在HTML的头部添加thymeleaf的约束
<!--添加头部,即可使用thymeleaf表达式-->
<html lang="en" xmlns:th="http://www.thymeleaf.org">
3.使用th标签
<div th:text="${msg}"></div>
<div th:utext="${msg}"></div>
<h3 th:each="user:${users}" th:text="${user}"></h3>
------------------------------
<h4 th:each="user:${users}">[[${user}]]</h4>