表单提交 th:action
<form th:action="@{/test/hello}" >
<input th:type="text" th:name="id">
<button>提交</button>
</form>
对象遍历 th:each
Integer id;
String name;
String address;
model.addAttribute("users",userList);
<table>
<tr>
<td>下标</td>
<td>编号</td>
<td>姓名</td>
<td>住址</td>
</tr>
<tr th:each="user,userStat:${users}">
<td>
下标:<span th:text="${userStat.index}"></span>,
</td>
<td th:text="${user.id}"></td>
<td th:text="${user.name}"></td>
<td th:text="${user.address}"></td>
</tr>
</table>
Map输出
dataMap.put("No","123");
dataMap.put("address","深圳");
model.addAttribute("dataMap",dataMap);
<div th:each="map,mapStat:${dataMap}">
<div th:text="${map}"></div>
key:<span th:text="${mapStat.current.key}"></span><br/>
value:<span th:text="${mapStat.current.value}"></span><br/>
</div>
数组输出
<div th:each="nm,nmStat:${names}">
<span th:text="${nmStat.count}"></span><span th:text="${nm}"></span>
</div>
日期输出
<span th:text="${#dates.format(now,'yyyy-MM-dd hh:ss:mm')}"></span>
条件判断 th:if
<span th:if="${(age>=18)}">成年了</span>
定义模块 th:fragment 引入模块 th:include
- 创建footer.html
<div id="C" th:fragment="ft" >
关于我们<br/>
</div>
- 引入footer模块
<div id="A" th:include="footer::ft"></div>