점프투스프링부트 추가기능 구현 세번째, 최근 답변 조회 입니다 (최근 댓글은 현재 댓글 기능 미구현으로 추후 추가 예정)
Repository 코드만 포스팅 하겠습니다. 혹시 참조하실 분들은 상세 코드는 아래 이슈를 참조해주세요
구현 방식
최근 답변 페이지
최근 답변 가져오기
List<Answer> findTop15ByOrderByCreateDateDesc();
최근 답변 페이지
<html layout:decorate="~{common/layout}">
<main layout:fragment="content" class="container my-3">
<div class="d-flex gap-4 align-items-center">
<H3>최근 답변</H3>
<h5 class="text-secondary">가장 최근에 달린 답변 15개까지 나타납니다.</h5>
</div>
<table class="table">
<thead class="table-dark">
<tr class="text-center">
<th>구분</th>
<th>글쓴이</th>
<th style="width:50%">제목(내용)</th>
<th>날짜</th>
</tr>
</thead>
<tbody>
<tr class="text-center" th:each="answer, loop : ${answerList}">
<td>-</td> <!-- TODO : 카테고리 후 수정 필요 -->
<td th:text="${answer.author.username}"></td>
<td class="text-start">
<a th:href="@{|/question/detail/${answer.question.id}#answer_${answer.id}|}">
<div class="d-flex gap-1">
<p th:if="${answer.question.subject.length() <= 10}" th:text="${'('+answer.question.subject + ')'}"></p>
<p th:if="${answer.question.subject.length() > 10}" th:text="${'('+answer.question.subject.substring(0,10) + '...)'}"></p>
<p th:if="${answer.content.length() <= 10}" th:text="${'('+answer.content + ')'}"></p>
<p th:if="${answer.content.length() > 10}" th:text="${'('+answer.content.substring(0,10) + '...)'}"></p>
</div>
</a>
</td>
<td th:text="${#temporals.format(answer.createDate, 'yyyy년 M월 d일 h:mm a')}"></td>
</tr>
</tbody>
</table>
</main>
</html>