首先,在pom.xml文件中添加Thymeleaf的依赖: <dependency> <groupId>org.springframework.boot
- 首先,在pom.xml文件中添加Thymeleaf的依赖:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
spring.thymeleaf.prefix=classpath:/templates/
spring.thymeleaf.suffix=.html
@Controller
publicclassMyController{
@RequestMapping("/myPage")
publicStringmyPage(Modelmodel){
model.addAttribute("message","Hello,Thymeleaf!");
return"myPage";
}
}
<!DOCTYPEhtml>
<htmlxmlns:th="http://www.thymeleaf.org">
<head>
<title>MyPage</title>
</head>
<body>
<h1th:text="${message}"></h1>
</body>
</html>
通过以上步骤,就可以实现SpringBoot整合Thymeleaf的功能。
版权声明
本文仅代表作者观点,不代表博信信息网立场。