java - 嵌套迭代百里香叶
问题描述
我想迭代一个嵌套的 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
)。
推荐阅读
- python - Python 中 sqlite 的 NoSQL 替代方案
- linux - 如何在 Linux 中查找占用磁盘空间的文件
- node.js - 将 SQL 翻译成 knex
- github - 在 GitHub 上查找具有特定文件类型的所有文件
- c# - unity c# 中的“for”循环延迟
- haskell - 隐式调用函数
- clojure - 如何反向减少以便从最后一个索引迭代直到 0 索引?
- scala - Maven Jar 文件找不到主类
- java - 使用 ByteArrayOutputStream 和 BufferedOutputStream 来避免内存问题,这是个好主意吗?
- python - 如何计算一个值在字典中出现的次数?