Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/378.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_Thymeleaf - Fatal编程技术网

Java Thymeleaf通过索引获取上一个对象

Java Thymeleaf通过索引获取上一个对象,java,thymeleaf,Java,Thymeleaf,如何通过索引获取上一个对象(例如iterStat-1) 此代码基于thymeleaf教程示例 名字 价格 有现货的 洋葱 2.41 对 我想要下面这样的东西 您可以通过 <td th:unless="${iterStat.first}" th:text="${prods[iterStat.index-1].price}"></td> th:except=“${iterStat.first}”将不会为第一个元素呈现单元格,因此您不会尝试获取索引-1的元素(将导致异

如何通过索引获取上一个对象(例如iterStat-1)

此代码基于thymeleaf教程示例


名字
价格
有现货的
洋葱
2.41
对
我想要下面这样的东西


您可以通过

<td th:unless="${iterStat.first}" th:text="${prods[iterStat.index-1].price}"></td>


th:except=“${iterStat.first}”
将不会为第一个元素呈现单元格,因此您不会尝试获取索引-1的元素(将导致异常)。

如果它按预期工作,请考虑接受答案;)