How can I loop by index?
Foo.java
public Foo {
private List tasks;
...
}
index.html
Thymeleaf always declares implicit iteration status variable if we omit it.
Here, the status variable name is taskStat
which is the aggregation of variable task
and the suffix Stat
.
Then in the loop, we can refer to taskStat.index
, taskStat.size
, taskStat.count
, taskStat.even
and taskStat.odd
, taskStat.first
and taskStat.last
.
Source: Tutorial: Using Thymeleaf - 6.2 Keeping iteration status