Themleaf結合spring boot使用
Themleaf的maven模闆引擎
<!--引入thymeleaf依賴-->
<dependency>
<groupId>org.thymeleaf</groupId>
<artifactId>thymeleaf-spring5</artifactId>
<!--<version></version>-->
</dependency>
<dependency>
<groupId>org.thymeleaf.extras</groupId>
<artifactId>thymeleaf-extras-java8time</artifactId>
<!--<version>3.0.4.RELEASE</version>-->
</dependency>
建立對應目錄結構
@Controller
public class MyController {
@RequestMapping("/")
public String toIndex(Model model){
model.addAttribute("msg", "hello");
return "index";
}
}
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<h1>
首頁
</h1>
<p th:text="${msg}"></p>
</body>
</html>