首页 > 解决方案 > 为什么不工作

问题描述

我正在尝试遍历包含对象列表的列表,即 List 我想知道为什么这不起作用,尝试简单地使用“i”,但没有运气。

List<Object[]> lists;  // logic
model.addObject("lists", lists);
model.addObject("table_width", lists.get(0).length);

Thymeleaf 代码片段

<table class="table table-responsive table-stripped table-collapsed table-bordered">
                <tr th:each="rows,rowStat : ${lists}">
                    <td th:text="${rowStat.count}"></td>

                    <td th:each="i : ${#numbers.sequence(0, table_width)}" th:text="${rows[${i}]}"></td>
                </tr>
</table>

标签: springspring-bootthymeleaf

解决方案


我找到了一个方法,

<td th:each="i : ${#numbers.sequence(0, table_width-1)}" th:text="${rows[__${i}__]}"></td>

这是诀窍


推荐阅读