ThymeLeaf 中的循环内循环

问题描述 投票:0回答:0

我错误地将这个问题作为对类似问题的答案发布 (https://stackoverflow.com/questions/19956493/nested-double-loop-with-thymeleaf)

我有一个班级

App
@ManyToOne
Cube
关系。

我正在尝试制作一个表格,其中每条记录代表一个

App
,并且在其中一个单元格中会列出相关的
Cube
对象。

<tr th:each="app : ${apps}">
  <td th:text="${app.id}">ID</td>
  <td th:text="${app.name}">Name</td>
  <td th:text="${app.description}">Description</td>
  <td th:text="${app.url}">URL</td>
  <td>
    <ul>
      <li th:each="cube : ${app.cubes}">
        <span th:text="${cube.name}">Name</span>
      </li>
    </ul>
  </td>
</tr>

我目前在数据库中有3个

App
s,每个有3-4个相关的
Cube
s.

App
行生成正确,但我只列出了一个
Cube
项目。碰巧的是,我注意到这两个对象的 id 都是
1

loops spring-thymeleaf
© www.soinside.com 2019 - 2024. All rights reserved.