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