http://www.thymeleaf.org/doc/tutorials/2.1/usingthymeleaf.html
http://blog.csdn.net/u012706811/article/details/52185345
springboot有很多默認(rèn)配置
默認(rèn)頁面映射路徑:classpath:/templates/*.html
靜態(tài)文件路徑為 classpath:/static/
springboot默認(rèn)使用themeleaf模板引擎
pom.xml添加依賴
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
在application.properties中配置themeleaf模板解析器屬性
spring.thymeleaf.mode=HTML5
spring.thymeleaf.encoding=UTF-8
spring.thymeleaf.content-type=text/html
#開發(fā)時關(guān)閉緩存,不然沒法看到實時頁面
# Allow Thymeleaf templates to be reloaded at dev time
spring.thymeleaf.cache=false
注意:在spring-boot下,默認(rèn)約定了Controller試圖跳轉(zhuǎn)中thymeleaf模板文件的前綴prefix是”classpath:/templates/”,后綴suffix是”.html”
添加themeleaf命名空間
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">
頁面demo
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">
<head>
<title>hello</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body>
<!--/*@thymesVar id="name" type="java.lang.String"*/-->
<p th:text="'Hello, ' + ${name} + '!'" ></p>
</body>
</html>
Controller層
@Controller
@RequestMapping("/themeleaf")
public class HelloThemeController{
@RequestMapping(value="/hello",method = RequestMethod.GET)
public String helloTheme(Model model){
model.addAttribute("name", "world");
return "/hello";
}
}