본문 바로가기

카테고리 없음

타임리프 게시판 페이징 소스

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
 <div>
 
            <nav aria-label="Page navigation example">
                <ul class="pagination"
                th:with="start=${T(Math).floor(boardDto.number/10)*10},
                last=(${start + 9 < boardDto.totalPages ? start + 9 : boardDto.totalPages})">
                    <li class="page-item">
                        <a class="page-link" th:href="@{/board(page=0)}" aria-label="First">
                            <span aria-hidden="true">First</span>
                        </a>
                    </li>
                    <li class="page-item" th:class="${boardDto.first} ? 'disabled'">
                        <a class="page-link" th:href="${boardDto.first} ? '#' : @{/board(page=${boardDto.number-1})}" aria-label="Previous">
                            <span aria-hidden="true">Previous</span>
                        </a>
                    </li>
                    <li class="page-item" th:each="page: ${#numbers.sequence(start,last-1)}" th:class="${page== boardDto.number} ? 'page-item active'">
                        <a class="page-link" th:href="@{board(page=${page})}" th:text="${page+1}">
                        </a>
                    </li>
                    <li class="page-item" th:class="${boardDto.last} ? 'disabled'">
                        <a class="page-link" th:href="${boardDto.last} ? '#' : @{/board(page=${boardDto.number+1})}" aria-label="Next">
                            <span aria-hidden="true">Next</span>
                        </a>
                    </li>
                    <li class="page-item">
                        <a class="page-link" th:href="@{/board(page=${boardDto.totalPages-1})}" aria-label="Last">
                            <span aria-hidden="true">Last</span>
                        </a>
                    </li>
 
                </ul>
            </nav>
        </div>
cs

부트스트랩 4 기준으로 했습니다.

흠이 있다면 페이지 1을 고르면 실제로는 페이지 0으로 나갑니다. 

실제로는 서버에서 -1 처리해주던가.. 해야될까요? 뭐가 더 효율적인진 모르겠지만

이제 작동은 되니까..

 

boardDto는 Page<boardDto> 입니다