Project/Study Website Project
[Spring Boot Project] 페이징 처리
seung_hyeon
2025. 1. 21. 00:19
PostController

@PageableDefault 설정
page: defalut 페이지 (0부터 시작)
size: 한 페이지 게시글 수
sort: 정렬 기준 칼럼
direction: 정렬 순서
Pageable - 몇 페이지인지 한 페이지에 보여줄 게시물 개수 몇 개인지 담아서 보낼 수 있음
@PageableDefault 사용해서 설정 (url에 페이지 정보와 사이즈 넘길 수 있음)
findAll - DB에 있는 모든 정보 가져오면 보관된 정보 모두 가져옴
PostList.html에 추가
<th:block th:each="page : ${#numbers.sequence(startPage, endPage)}">
<a th:if="${page != nowPage}" th:href="@{/post/list(page = ${page - 1})}" th:text="${page}"></a>
<strong th:if="${page == nowPage}" th:text="${page}" style="color : red"></strong>
</th:block>
Thymeleaf 문법
th:each = 반복문
th:each = "${number: #number(시작번호, 끝번호)}"
시작 번호에서 끝번호까지 반복
- 원래 페이지
새게시글 가장 밑에 업로드, 모든 게시글이 한 페이지에 뜸

- 수정 후 페이지
새 게시글이 가장 위에 업로드 / 한 페이지에 10개씩

