【发布时间】:2020-10-18 18:12:43
【问题描述】:
如何按索引循环?
Foo.java
public Foo {
private List<String> tasks;
...
}
index.html
<p>Tasks:
<span th:each="${index: #numbers.sequence(0, ${foo.tasks.length})}">
<span th:text="${foo.tasks[index]}"></span>
</span>
</p>
我遇到了解析错误
org.thymeleaf.exceptions.TemplateProcessingException: Could not parse as each: "${index: #numbers.sequence(0, ${student.tasks.length})}"
【问题讨论】:
-
既然已经可以遍历集合,为什么还需要使用索引?
-
最后,我想将列表转换为逗号分隔的字符串。我想检查该项目是否是最后一个元素。所以我必须先按索引循环。
标签: java jakarta-ee thymeleaf each