首先在html開始標簽中引入一個屬性
xmlns:th="http://www.thymeleaf.org"
遍歷數據示例
<tbody> <tr th:each="user:${users}"> <td th:text="${user.name}"></td> <td th:text="${user.email}"></td> <td><a th:href="@{/edit/{id}(id=${user.id})}">修改</a></td> <td><a th:href="@{/delete/{id}(id=${user.id})}">刪除</a></td> </tr> </tbody>
在html標簽里寫th屬性,th:each相當於java代碼的for each循環
th:text則相當於value屬性然后用${變量名}取數據