引入thymeleaf
<html xmlns:th="http://www.thymeleaf.org">
一、变量表达式 ( ${...} )
<span th:text="${book.author.name}"></span>
二、消息表达式 ( #{...} )
<th th:text="#{header.address.city}"></th>
三、选择表达式 ( *{...} )
<div th:object="${book}">
<span th:text="*{title}"></span>
</div>
四、链接表达式 ( @{...} )
<!-- 链接表达式可以是相对的,在这种情况下,应用程序上下文将不会作为URL的前缀 -->
<a th:href="@{../devsoft/thymeleaf}"></a>
<!-- 也可以是服务器相对的(同样没有应用程序上下文前缀) -->
<a th:href="@{~/content/main}"></a>
<!-- 和协议相对(就像绝对url,但浏览器将使用在显示的页面中使用的相同的HTTP或HTTPS协议) -->
<a th:href="@{//static.com}"></a>
<!-- url绝对 -->
<a th:href="@{http://www.baidu.com}"></a>
五、设置属性值
<input th:attr="value=#{book.name}">
<input th:value="#{book.name}">
六、迭代器 ( 遍历 -> th:each )
<li th:each="book : ${book}" th:text="${book.title}"></li>
// 状态变量
index、count、size、current、even/odd、first、last
七、条件语句
<!-- th:if="${ aa == bb}" -->
<!-- th:unless="${aa == bb}" -->
<!-- th:switch -->
<div th:switch="${user.name}">
<p th:case="Tom">success</p>
<p th:case="#{roles.manager}">success</p>
<p th:case="*">success</p>
</div>
八、模板布局
<div id="copy">
© test
</div>
<!--
<div th:fragment="copy">
© test
</div>
-->
<div th:insert="~{index :: #copy}">123</div>
<div th:replace="~{index :: #copy}">123</div>
<div>123</div>
九、属性优先级
十、内联表达式
<!-- th:utext 对应 [(...)] -->
<p>The message is "[(${msg})]"</p> --> <p>The message is "This is <b>greet!</b>"</p>
<!-- th:text 对应 [[...]] -->
<p>The message is "[[${msg}]]"</p> --> <p>The message is "This is <b>greet!</b>"</p>
<!-- 只想使用[()]、[[]]这两个符号,不启用内联表达式,在标签内使用th:inline=none -->
<p th:inline="none"></p>
十一、和SpringBoot集成
// 引入thymeleaf依赖
compile('org.springframework.boot:spring-boot-starter-thymeleaf:2.0.3.RELEASE')
#application.properties配置
#thymelea模板配置
#spring.thymeleaf.prefix=classpath:/templates/
#spring.thymeleaf.suffix=.html
spring.thymeleaf.mode=HTML5
spring.thymeleaf.encoding=UTF-8
#热部署文件,页面不产生缓存,及时更新
spring.thymeleaf.cache=false
spring.resources.chain.strategy.content.enabled=true
spring.resources.chain.strategy.content.paths=/**
十二、