<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
spring.thymeleaf.cache=false
# 默认前置
spring.thymeleaf.prefix=classpath:/templates/
# 默认后缀
spring.thymeleaf.suffix=.html
@Controller
public class HelloThymeleafController {
@RequestMapping("/hello")
public String hello(Model model){
model.addAttribute("hello","hello welcome");
// 找classpath:/templates/hello.html
return "hello";
}
}
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<title>Thymeleaf的入门</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
</head>
<body>
<!--输出hello数据-->
<p th:text="${hello}"></p>
</body>
</html>