我在 Thymeleaf
中找不到构建简单 for-each 循环的语法模板。
我对 th:each=""
不满意属性,因为它复制了它所在的标签。
我正在寻找的是这样的东西:
<th:foreach th:each="...">
...block to be repeated...
</th>
什么是 <c:forEach items="..." var="...">
的类似物或 <t:loop source="..." value="...">
在 Tapestry
.有没有类似的东西?
最佳答案
使用 th:block
正如 Thymeleaf 指南中所述
th:block
只是一个属性容器,允许模板开发人员指定他们想要的任何属性。 Thymeleaf 将执行这些属性,然后简单地使 block 消失得无影无踪。
因此它可能很有用,例如,在创建需要多个 <tr>
的迭代表时对于每个元素:
<table>
<th:block th:each="user : ${users}">
<tr>
<td th:text="${user.login}">...</td>
<td th:text="${user.name}">...</td>
</tr>
<tr>
<td colspan="2" th:text="${user.address}">...</td>
</tr>
</th:block>
</table>
关于spring - 对于 Thymeleaf 中的每个运算符(operator),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53173202/