对于Thymeleaf中的每个运算符


问题内容

我找不到在Thymeleaf模板中构建简单的for-each-loop的语法。我对just
th:each=""属性不满意,因为它复制了它所在的标签。

我正在寻找的是这样的:

<th:foreach th:each="...">
...block to be repeated...
</th>

<c:forEach items="..." var="..."><t:loop source="..." value="...">在…中的类似物Tapestry。有类似的东西吗?


问题答案:

th:block如胸腺叶指南中所述使用

th:block仅是一个属性容器,允许模板开发人员指定所需的任何属性。Thymeleaf将执行这些属性,然后简单地使该块消失而没有任何痕迹。

因此,例如在创建<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>