1、pom.xml中加入Thymeleaf可以不指定版本,默认为最新的
<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-thymeleaf -->
<!-- Thymeleaf是一个Java模板引擎开发库,可以处理和生成HTML、XML、JavaScript、CSS和文本,在Web和非Web环境下都可以正常工作-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
<version>2.1.0.RELEASE</version>
</dependency>
2、在templates存放HTML文件
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<h1>主页</h1>
<span th:text="${key}"></span>
</body>
</html>
3、application.yml文件中添加Thymeleaf的配置,这里只指定了存放HTML文件的路径
4、访问