thymeleaf头文件
- html引入thymeleaf
<html xmlns:th="http://www.thymeleaf.org">
赋值
//会替换原来的值
<h1 th:text="aaa">123</h1>
//取model中msg的值
<h1 th:text="${msg}">123</h1>
<input th:value="${msg}">
判断
//判断优先级高,先判断后生成(判断msg中是否为空)
<p style="color: red" th:text="${msg}" th:if="${not #strings.isEmpty(msg)}"></p>
遍历
遍历1-5
<a th:each="i:${#numbers.sequence(1,5)}" th:text="${i}"></a>
遍历集合
<p th:each="user:${list}" th:text="${user}"></p>
链接拼接
<img th:src="@{/img/research/{filename}(filename=${research.filename})}">
<a th:href="@{/user/pwd/}+${user.userCode}">
模板提取公共页面
<!--需要提取的公共页面上加上th:fragment+片段名 -->
<p th:fragment="hello">hello world</p>
<!--使用公共片段,公共页面名称(如果放在包下需要路径名)::片段名(也支持选择器) -->
替换,效果,当前标签被替换成公共片段
<div th:replace="common :: head"></div>
插入,效果:将公共片段插入到当前标签中,片段会被当前标签包裹
<div th:replace="common :: head"></div>
包含,效果:引入公共片段中内容,会将片段内容直接放在当前标签中
<div th:include="common :: head"></div>