Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/367.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/81.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 在thymeleaf中执行迭代时添加序列号_Java_Html_Spring_Web_Thymeleaf - Fatal编程技术网

Java 在thymeleaf中执行迭代时添加序列号

Java 在thymeleaf中执行迭代时添加序列号,java,html,spring,web,thymeleaf,Java,Html,Spring,Web,Thymeleaf,我有一个senario,其中我必须在列表上执行迭代,并将结果显示为网格。还包括序列号。下面给出了我对序列号所做的操作 <div th:with="i=0"> <tr th:each="mydate:${data.Listdata}" > <div th:with="i=${i+1}"> <td th:text="${i}"> </div> //other codes </tr> </div&g

我有一个senario,其中我必须在列表上执行迭代,并将结果显示为网格。还包括序列号。下面给出了我对序列号所做的操作

<div th:with="i=0">
 <tr th:each="mydate:${data.Listdata}" >
  <div th:with="i=${i+1}">
   <td th:text="${i}">
  </div>
    //other codes
 </tr>
</div>

//其他代码

但是所有序列号中只有1。有人能帮我吗?

您可以使用迭代状态的索引:

<tr th:each="item,iterator : ${items}">
    <td th:text="${iterator.index}"></td>
</tr>

您可以使用iterationStatus以1而不是0开头

 <tr th:each="item,iterationStatus : ${items}">
    <td th:text=${iterationStatus.count}></td>
 </tr>

这使得表Sno。从1开始