Thymeleaf - How to loop a list by index

前端 未结 2 1085
礼貌的吻别
礼貌的吻别 2020-12-08 09:25

How can I loop by index?

Foo.java

public Foo {
    private List tasks;
    ...
}

index.html



        
2条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-08 10:16

    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

提交回复
热议问题