一、常用语法 1.th:text 替换文本
[html] view plain copy
<p th:text="${x.a}">被替换文本</p>
2.字符串拼接
[html] view plain copy
<p th:text="${'拼接块'+x.a+'拼接块'+x.b+'拼接块'}" >被替换文本</p>
3.遍历List
[html] view plain copy
<tr th:each="x:${xList}">
<th th:text="${x.a}">被替换文本</th>
<th th:text="${x.b+' '+x.c}" >被替换文本</th>
</tr>
4.格式化日期
[html] view plain copy
th:text="${#dates.format(x.y, 'yyyy-MM-dd HH:mm:ss')}"
二、引入外部文件: 1.@{}的方式引入外部文件会包含项目名
[html] view plain copy
css: th:href="@{/css/***.css}"
js: th:src="@{/js/***.js}"
img: th:src="@{/img/***.png}"
2.include引入文件 (1)模板文件引入layout,并且声明decorator=“自定义X”
[html] view plain copy
<html xmlns:th="http://www.thymeleaf.org"
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
layout:decorator="web-model">
(2)模板文件写入内容,th:fragment=“自定义Y”。ps:th:remove=“tag”为了删掉外边包围着的div
[html] view plain copy
<div th:fragment="left" th:remove="tag">
***模板内容***
(3)需要引入的模板文件的html
[html] view plain copy
<div th:include="web-model(自定义X)::left(自定义Y)" ></div>
(4)结果
[html] view plain copy
“<div th:include="web-model(即自定义X)::left(即自定义Y)" ></div>” 替换成 “***模板内容***”
本文转载自:https://blog.csdn.net/u014155085/article/details/79175071