th属性
th:text 文本替换
th:value 值替换
th:object 父标签选择对象,子标签使用*{}取值
html1
2
3<div th:object="${session.user}">
<p th:text="*{name}">name</p>
</div>th:each 遍历
html1
2
3
4
5<div th:each="c:${category[0]}" th:text="${c.categoryname}"></div>
<div th:each="c:${category}">
<label><input type="checkbox" th:value="${c.name}">[[${c.name}]]</label>
</div>th:if 条件判断
html1
<a th:if="${id==collect.id}"></a>
th:selected 选择框选中
html1
2
3<select>
<option th:selected="${name=='a'}"></option>
</select>th:src 替换src
html1
<img th:src="@{/img/test.png}" width="350px" height="250px">
th:action 替换表单提交地址
html1
<form th:action="@{/login}" th:method="post"></form>
th:href 替换链接路径
html1
<a th:href="@{/task/task_add}"></a>
th:fragment 定义片段名字,可以被引用
th:replace/insert 使用th:fragment定义的片段替换/插入当前标签
html1
2
3<footer th:fragment="footer" id="test"></footer>
<div th:replace="~{common/footer::footer(Url='task/task_add')}"></div>
<div th:replace="common/footer::#test(Url='task/task_add')"></div>
SpringBoot整合Thymeleaf(通过添加模板属性)
java
1 | import org.springframework.ui.Model; |
html
1 | <div th:text="{users[0].name}"></div> |