spring - 对于 Thymeleaf 中的每个运算符(operator)

标签 spring spring-mvc for-loop foreach thymeleaf

我在 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/

相关文章:

java - Spring OAuth2 自定义认证管理器 ClassCastException

spring - org.hibernate.exception.GenericJDBCException : Cannot open connection

java - 当子项更改时如何更新根实体上的modified_at列?

java - junit - 测试从未实例化的类的私有(private)方法

java - Spring Boot - POST 请求方法不起作用,但 GET 起作用

r - 忽略循环中的错误,使用循环命名数据帧

java - 尽管调用了该方法,为什么 AbstractMvcEndpoint 的子类仍返回 404?

java - Maven 3.2.5 中的 Flexmojo 支持

syntax - 有人可以为我解释一下吗 - for (int i = 0; i < 8; i++)

loops - VBscript错误处理-移至 “For Each”循环中的下一项