@PreAuthorize("isAuthenticated()")
@GetMapping("/me")
public String me(Model model, @RequestParam(value = "page", defaultValue = "0") int page,
@RequestParam(value = "page2", defaultValue = "0") int page2, Principal principal) {
SiteUser user = userService.getUser(principal.getName());
Page<Question> paging = questionService.getUserQuestionList(page, user.getId());
Page<Answer> answerPage = answerService.getUserAnswerList(page2, user.getId());
model.addAttribute("SiteUser", user);
model.addAttribute("paging", paging);
model.addAttribute("answerPaging", answerPage);
return "member_me";
}
내가 작성한 질문에 대해서 찾아오기 위해서 어디서 가져와야 할까 생각을 해보니 Questionrepository에 authorid를 통해서 리스트를 받아서 페이징 진행.
Page<Question> findByAuthorId(Pageable pageable,Long id);
<div th:if="${!paging.isEmpty()}">
<ul class="pagination justify-content-center">
<li class="page-item" th:classappend="${!paging.hasPrevious} ? 'disabled'">
<a class="page-link"
th:href="@{|?page=${paging.number-1}|}">
<span>이전</span>
</a>
</li>
<li th:each="page: ${#numbers.sequence(0, paging.totalPages-1)}"
th:if="${page >= paging.number-5 and page <= paging.number+5}"
th:classappend="${page == paging.number} ? 'active'"
class="page-item">
<a th:text="${page}" class="page-link" th:href="@{|?page=${page}|}"></a>
</li>
<li class="page-item" th:classappend="${!paging.hasNext} ? 'disabled'">
<a class="page-link" th:href="@{|?page=${paging.number+1}|}">
<span>다음</span>
</a>
</li>
</ul>
</div>
답변 부분도 추가 진행
<!--
내가 작성한 답변들 리스트 나오게.
-->
<h3 class="text-center">내가 작성한 답변들</h3>
<table class="table">
<thead class="table-dark">
<tr class="text-center">
<th style="width:50%">내용</th>
<th>글쓴이</th>
<th>작성일시</th>
</tr>
</thead>
<tbody>
<tr class="text-center" th:each="answer, loop:${answerPaging}">
<td class="text-start">
<a th:href="@{|/question/detail/${answer.question.id}|}" th:utext="${answer.content}"></a>
</td>
<td><span th:text="${answer.author.username}"></span></td>
<td th:text="${#temporals.format(answer.createDate, 'yyyy-MM-dd HH:mm')}"></td>
</tr>
</tbody>
</table>
<!-- 페이징처리 시작 -->
<div th:if="${!answerPaging.isEmpty()}">
<ul class="pagination justify-content-center">
<li class="page-item" th:classappend="${!answerPaging.hasPrevious} ? 'disabled'">
<a class="page-link"
th:href="@{|?page2=${answerPaging.number-1}|}">
<span>이전</span>
</a>
</li>
<li th:each="page2: ${#numbers.sequence(0, answerPaging.totalPages-1)}"
th:if="${page2 >= answerPaging.number-5 and page2 <= answerPaging.number+5}"
th:classappend="${page2 == answerPaging.number} ? 'active'"
class="page-item">
<a th:text="${page2}" class="page-link" th:href="@{|?page2=${page2}|}"></a>
</li>
<li class="page-item" th:classappend="${!answerPaging.hasNext} ? 'disabled'">
<a class="page-link" th:href="@{|?page2=${answerPaging.number+1}|}">
<span>다음</span>
</a>
</li>
</ul>
</div>
<!-- 페이징처리 끝 -->
</div>
이렇게 내 정보 화면에서 간단한 내 정보와 내가한 질문 및 답변들을 페이징 형식으로 나오게 변경하였다.