<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
spring.thymeleaf.prefix=classpath:/templates/
spring.thymeleaf.suffix=.html
@Controller
public class MyController {
@RequestMapping("/myPage")
public String myPage(Model model) {
model.addAttribute("message", "Hello, Thymeleaf!");
return "myPage";
}
}
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<title>My Page</title>
</head>
<body>
<h1 th:text="${message}"></h1>
</body>
</html>
通過以上步驟,就可以實現Spring Boot整合Thymeleaf的功能。