HTML , CSS , JS
th:each 역순으로 나타내기
주탱2
2022. 11. 1. 01:07
List에 담아온 목록들을 역순으로 나타내고 싶을 때가 있다.
최근 등록한 게시물이 제일 앞으로 나타났으면 좋겠다.
<div id="boardList" th:each="capsule : ${capsuleList}">
현재 상태는 3번으로 등록한 게시물이 제일 나중에 나타나고 있다.
th : with 와 #numbers.sequence(start, end, step)를 이용해서 역순으로 나타낼 수 있음.
<div id="boardList" th:each="i : ${#numbers.sequence(capsuleList.size()-1, 0, -1)}"
th:with="capsule=${capsuleList[i]}">
위 그림과 같이 원하는 대로 3번 게시물이 제일 처음으로 온 것을 볼 수 있다.
참고 : https://devwithpug.github.io/spring/thymeleaf/
Thymeleaf - 유용한 문법 정리
개요
devwithpug.github.io