为此,出现了 iterStat 这样的东西。是一种用于跟踪迭代状态的有用机制:状态变量。 这展示了如何输出 5 个项目,然后移至新行。
<table>
<tr th:each="product, iterStat : ${data}">
<td>
<input type="checkbox" name="productCode" th:value="${product.productCode}" th:text="${product.productName}" />
</td>
<th:block th:if="${iterStat.count % 5 == 4 and !iterStat.last}">
</tr><tr>
</th:block>
</tr>
</table>