使用thymeleaf迭代索引

Dee*_*ass 13 html html5 spring jsp thymeleaf

我是thymeleaf的新手,正在将我的所有jsp代码转换为thymeleaf.我不知道如何将以下代码转换为thymeleaf.有谁知道如何将以下代码转换为thymeleaf

<logic:iterate id="id" property="idList" name="sampleForm" indexId="i">
    <label for="id<%=i%>">
      <bean:write name="id" property="id" />
    </label>
</logic:iterate>
Run Code Online (Sandbox Code Playgroud)

请告诉我如何初始化索引值thymeleaf以用于某些值?

Tom*_*lst 18

<label th:each="id,status : ${idList}" th:for="|id${status.index}|" th:text="${id.id}"></label>
Run Code Online (Sandbox Code Playgroud)
  • th:each将迭代idList,分配每个项目idlabel为每个项目创建一个.可以通过添加额外的名称来指定项目的状态,以逗号分隔(status在此示例中).
  • th:for将设置for标签的属性.管道(|)用于简单的字符串连接.
  • th:text 将标签的内部文本设置为ID.