我想迭代嵌套的 ArrayList,因此输出类似于:
* 1
* 1
* 2
* 3
* 4
* 2
* 1
* 2
* 3
* 4
* 3
* 1
* 2
* 3
* 4
相反,thymeleaf 在第一次迭代中检索所有对象,我得到:
* 1
* 1
* 2
* 3
* 4
* 1
* 2
* 3
* 4
* 1
* 2
* 3
* 4
* 2
* 3
我的代码是:
<ul th:each="row, row_iterator: ${theater.getRows()}">
<li th:text="${row.getId()}"> </li>
<ul th:each="seat, seat_iterator: ${row.getSeats()}">
<li th:text="${seat.getId()}"> </li>
</ul>
</ul>
最佳答案
我认为您的 html 格式错误。这对你有用吗?
<ul>
<li th:each="row: ${theater.rows}">
<span th:text="${row.id}" />
<ul>
<li th:each="seat: ${row.seats}" th:text="${seatid}" />
</ul>
</li>
</ul>
一些注意事项:
- 您可以使用 Javabean 格式约定来缩短所有内容(例如,
row.getId()
可以缩短为row.id
)。
关于java - 嵌套迭代 thymeleaf ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56041761/