10
인덱스로 어떻게 루프 할 수 있습니까?Thymeleaf - 인덱스별로 목록을 반복하는 방법
Foo.java 내가
org.thymeleaf.exceptions.TemplateProcessingException: Could not parse as each: "${index: #numbers.sequence(0, ${student.tasks.length})}"
인덱스로 어떻게 루프 할 수 있습니까?Thymeleaf - 인덱스별로 목록을 반복하는 방법
Foo.java 내가
org.thymeleaf.exceptions.TemplateProcessingException: Could not parse as each: "${index: #numbers.sequence(0, ${student.tasks.length})}"
Thymeleaf th:each
당신이 변수 반복 상태를 선언 할 수 있습니다 구문 분석 오류가 발생했습니다
public Foo {
private List<String> tasks;
...
}
index.html을
<p>Tasks: <span th:each="${index: #numbers.sequence(0, ${foo.tasks.length})}">
<span th:text="${foo.tasks[index]}"></span>
</span></p>
<span th:each="task,iter : ${foo.tasks}">
다음 루프에서 iter.index
및 iter.size
을 참조 할 수 있습니다.
는 http://www.thymeleaf.org/doc/tutorials/2.1/usingthymeleaf.html#keeping-iteration-status
왜 당신은 이미 단지 컬렉션을 반복 할 때 인덱스를 사용해야합니까 참조? –
결국 목록을 쉼표로 구분 된 문자열로 변환하고 싶습니다. 항목이 마지막 요소인지 확인하고 싶습니다. 그래서 나는 먼저 색인으로 반복해야합니다. – richersoon