前端遍历所有信息代码:
<table class="layui-table" id="test">
<colgroup>
<col width="150">
<col width="200">
<col>
</colgroup>
<thead>
<tr>
<th>id</th>
<th>作者</th>
<th>留言</th>
<th>会员等级</th>
<th>操作</th>
</tr>
</thead>
<tbody>
<tr th:each="user: ${msgList}"> <!--接收前端msgList值赋给user,th:each遍历所有数据-->
<td th:text="${user.id}"></td>
<td th:text="${user.author}"></td>
<td th:text="${user.msg}"></td>
<td th:text="${user.vexp}"></td>
<td>
<a th:href="@{/toUpdate(id=${user.id})}">修改</a>
<a th:href="@{/delete(id=${user.id})}">删除</a>
</td>
</tr>
</tbody>
</table>
id主键看起来不整齐,可以通过key.index+1排序
代码实现:
<tr th:each="user,key: ${msgList}"> <!--改动 user,key-->
<td th:text="${key.index+1}"></td> <!--改动 key.index+1 实现id有序排列-->
<td th:text="${user.author}"></td>
<td th:text="${user.msg}"></td>
<td th:text="${user.vexp}"></td>
<td>
<a th:href="@{/toUpdate(id=${user.id})}">修改</a>
<a th:href="@{/delete(id=${user.id})}">删除</a>
</td>
</tr>