Home  >  Q&A  >  body text

java - Thymeleaf中each标签遍历list如何获取index

应用程序采用sprigmvc,Thymeleaf来作为view层的数据展示。页面中试用th:each标签来遍历后端传来的List。需要取到index。

大家讲道理大家讲道理2764 days ago810

reply all(2)I'll reply

  • 大家讲道理

    大家讲道理2017-04-17 15:18:33

    <tr th:each="user,userStat:${users}">
    userStat is a status variable with attributes such as index, count, size, current, even, odd, first, last, etc. If the status variable is not set explicitly, thymeleaf will default to "variable name + Stat" "'s state variable.

    reply
    0
  • 天蓬老师

    天蓬老师2017-04-17 15:18:33

    The official document I read here is that the state variables are called iterStat by default. It is possible to test it yourself.

    reply
    0
  • Cancelreply