1、添加依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
2、写Controller
@Controller
public class IndexController {
@RequestMapping(value = "/index")
public String index(Model model){
model.addAttribute("data","Springboot 框架集成 Thymeleaf");
return"index";
}
}
3、写html文件
在html中添加
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<div th:text="${data}">xxx</div>
</body>
</html>
4、写主配置文件
关闭缓存
#设置thymeleaf模板引擎的缓存
spring.thymeleaf.cache=false
#设置thymeleaf模板引擎的前后缀
spring.thymeleaf.prefix=classpath:/templates/
spring.thymeleaf.suffix=.html
5、更改工件配置文件
修改为?
Update resources
Update resources
|