Spring Thymeleaf中数组的最后一个元素

Spring Thymeleaf中数组的最后一个元素,spring,spring-boot,thymeleaf,Spring,Spring Boot,Thymeleaf,我如何知道当前迭代是否是最后一次 <th:block th:each="err: ${#fields.errors('confirmedPassword')}"> [[${err}]], </th:block> [${err}]], 如您所见,每个错误消息后都会放置一个逗号。但是,我想在最后一次迭代后加上一个句号。您可以使用该变量。它有一个属性last,在上一次迭代时设置为true。像这样的方法应该会奏效: <th:block t

我如何知道当前迭代是否是最后一次

<th:block th:each="err: ${#fields.errors('confirmedPassword')}">
    [[${err}]], 
</th:block>

[${err}]],
如您所见,每个错误消息后都会放置一个逗号。但是,我想在最后一次迭代后加上一个句号。

您可以使用该变量。它有一个属性
last
,在上一次迭代时设置为true。像这样的方法应该会奏效:

<th:block th:each="err, status: ${#fields.errors('confirmedPassword')}">
  [[${err}]][# th:unless="${status.last}"],[/] 
</th:block>

[[${err}][#th:除非=“${status.last}]”,[/]
这对我很有用:

<th:block th:each="errMsg, errStatus: ${#fields.errors('confirmedPassword')}">
    <th:block th:text="!${errStatus.last} ? ${errMsg} + ', ' : ${errMsg} + '.'"></th:block>
</th:block>

感谢您的努力,但不幸的是,示例不起作用。但是你发布的链接非常有用。我马上就要发布正确的代码了。