#3 : 게시물에 일련번호 추가하기
01. 게시물 번호가 1부터 시작되는 문제
- 1페이지일 때도, 2페이지일 때도 게시물의 번호가 1부터 시작된다.
02. 게시물 번호 공식 만들기
- 질문 게시판의 번호를 역순으로 정렬, 1페이지부터 페이지 넘버가 시작하면 현재페이지-1
번호 = 전체 게시물 개수 - (현재 페이지 * 페이지당 게시물 개수) - 나열 인덱스
03. 게시물 번호 공식을 적용
- question_list.html의 번호 부분 수정
<tbody>
<tr th:each="question, loop : ${paging}">
<td th:text="${paging.getTotalElements - ((paging.number-1) * paging.size) - loop.index}"></td>
<td>
<a th:href="@{|/question/detail/${question.id}|}"
th:text="${question.subject}"></a>
</td>
<td th:text="${#temporals.format(question.createDate, 'yyyy-MM-dd HH:mm')}"></td>
</tr>
</tbody>

#4 : 답변 개수 표시
01. question_list.html 수정
<tbody>
<tr th:each="question, loop : ${paging}">
<td th:text="${paging.getTotalElements - ((paging.number-1) * paging.size) - loop.index}"></td>
<td>
<a th:href="@{|/question/detail/${question.id}|}"
th:text="${question.subject}"></a>
<span class="text-danger small ms-2"
th:if="{#lists.size(question.answerList)>0}"
th:text="${#lists.size(question.answerList))}">
</span>
</td>
<td th:text="${#temporals.format(question.createDate, 'yyyy-MM-dd HH:mm')}"></td>
</tr>
</tbody>

* th:if="{#lists.size(question.answerList)>0}" : 질문 객체의 답변 리스트의 크기가 0보다 큰 지 조사
* th:text="${#lists.size(question.answerList))}" : 답변 개수를 표시
'T-I-L > [책] 요약&정리' 카테고리의 다른 글
| [점프 투 스프링부트] 3장 SBB 서비스 개발(회원가입) - 2023. 08. 28. (0) | 2023.08.28 |
|---|---|
| [점프 투 스프링부트] 3장 SBB 서비스 개발(스프링 시큐리티) - 2023. 08. 24. (0) | 2023.08.25 |
| [점프 투 스프링부트] 3장 SBB 서비스 개발(내비게이션바, 페이징) - 2023. 08. 22. (0) | 2023.08.22 |
| [점프 투 스프링부트] 2장 스프링부트의 기본 요소(템플릿상속, 질문등록과폼, 공통템플릿) - 2023. 08. 21. (0) | 2023.08.21 |
| [점프 투 스프링부트] 2장 스프링부트의 기본 요소(답변등록,부트스트랩) - 2023. 08. 18 (0) | 2023.08.18 |
