我对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>

请告诉我如何初始化要在某些值中使用的thymeleaf中的索引值??

最佳答案

<label th:each="id,status : ${idList}" th:for="|id${status.index}|" th:text="${id.id}"></label>

th:each将迭代idList,将每个项分配给id并为每个项创建一个label。可以通过添加一个额外的名称来分配项目的状态,名称之间用逗号分隔(status在本例中)。
th:for将设置标签的for属性。管道(|)用于简单的字符串连接。
th:text将标签的内部文本设置为ID。

关于html - 使用thymeleaf迭代索引,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/20944800/

10-11 22:28
查看更多