GitHub:https://github.com/thymeleaf/thymeleaf
SpringBoot Starter:https://docs.spring.io/spring-boot/docs/current/reference/html/using-spring-boot.html#using-boot-starter
1、导入starter
<!--Thymeleaf-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
thymeleaf属性类ThymeleafProperties
2、contoller编写
/**
* @Description
* 在templates下的所有页面,只能通过controller跳转。
* 需要模板引擎的支持。
* @Author Administrator
* @Date 2020/12/10 12:27
*/
@Controller
public class IndexController {
@RequestMapping("/test")
public String index(){
return "test";
}
}
3、templates目录下新建一个html
4、所有的html元素都可以被thymeleaf接管
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<!--所有的html元素都可以被thymeleaf接管:th:元素名-->
<body>
<div th:text="${msg}"></div>
</body>
</html>