模板布局
th:fragment
示例
templates/footer.html
<!DOCTYPE html SYSTEM "http://www.thymeleaf.org/dtd/xhtml1-strict-thymeleaf-4.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
<body>
<div th:fragment="copy">
© 2011 The Good Thymes Virtual Grocery
</div>
</body>
</html>
templates/index.html中使用
<body> ...
<div th:include="footer :: copy"></div>
</body>
或者
...
<div id="copy-section">
© 2011 The Good Thymes Virtual Grocery
</div>
...
使用
<body> ...
<div th:include="footer :: #copy-section"></div>
</body>
th:include 和 th:replace 区别
th:include 加入代码
th:replace 替换代码
模板传参:参数传递顺序不强制
定义
<div th:fragment="frag (onevar,twovar)">
<p th:text="${onevar} + ' - ' + ${twovar}">...</p>
</div>
使用
<div th:include="::frag (${value1},${value2})">...</div>
<div th:include="::frag (onevar=${value1},twovar=${value2})">...</div>
等价于 <div th:include="::frag" th:with="onevar=${value1},twovar=${value2}">)