1.pom文件引入
<!-- spring boot thymeleaf-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
2.application.yml配置
spring:
# thymeleaf配置
thymeleaf:
prefix: classpath:/templates/
check-template-location: true
suffix: .html
encoding: UTF-8
content-type: text/html
mode: HTML5
cache: false
3.Controller类
@RequestMapping("/index")
public String index(Map<String, Object> map) {
map.put("name","Thymeleaf你好啊...");
return "index";
}
4.html页面
页面位置/src/java/resources/templates
页面名称:index.html
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8" />
<title></title>
</head>
<body>
${name}
</body>
</html>