- 创建一个springboot工程,导入以下依赖
<dependencies>
<!--springboot框架web组件依赖-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<!--springboot集成tyhmeleaf模板引擎-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
- 可以配置关闭页面缓存,实现项目的热更新
# 设置thymeleaf模板引擎的前/后缀(可以选项),如下(默认会找resources/templates/xx.html)
spring.thymeleaf.prefix=classpath:/templates/
spring.thymeleaf.suffix=.html
# 关闭页面缓存,默认是true
spring.thymeleaf.cache=false
3. html页面引入thymeleaf调度器
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<!--
xmlns:th="http://www.thymeleaf.org"引入thymeleaf模板引擎中央调度器
-->
<body>
<h1 th:text="${data}"></h1>
</body>
</html>
- IndexContrller测试类
@Controller
public class IndexController {
@RequestMapping("/index")
public String index(Model model) {
model.addAttribute("data", "hello world");
return "index";
}
}