首先,在html页面中要使用Thymeleaf模板引擎需要引入
<html xmlns:th = "http://www.thymeleaf.org"
xmlns:layou="http://www.ultraq.net.nz/thymeleaf/layout">
使用 th:replace 引入公共模板,fragments 为包名,header为html页面名,header为header页面中命名的片段名
<div th:fragment="header">
<div th:replace="~{fragments/header :: header}"></div>
HTML中画表格,${}变量表达式,其中可以为从后端传入的值,*{}变量表达式,为${}中传来的属性值,@{}链接表达式,其中可以为后端接口。
<table border="1">
<thead>
<tr>
<td>ID</td>
<td>Name</td>
<td>Email</td>
</tr>
</thead>
<tbody>
<tr th:if="${userModel.userList.size()} eq 0">
<td colspan="3">没有用户信息!</td>
</tr>
<tr th:each="user : ${userModel.userList}">
<td th:text="${user.id}">1</td>
<td th:text="${user.name}">zsp</td>
<td th:text="${user.email}">kkk</td>
<td ><a th:href="@{'/users/' + ${user.id}}" th:text="详情"></a> </td>
</tr>
</tbody>
</table>
啊啊啊啊啊啊,写的啥,完全不知道写啥啊,过几天自己看肯定都看不懂啊