점프 투 스프링부트 추가 기능 - 최근 답변 조회

박철현·2023년 7월 31일
0

점프투스프링부트

목록 보기
4/14
  • 점프투스프링부트 추가기능 구현 세번째, 최근 답변 조회 입니다 (최근 댓글은 현재 댓글 기능 미구현으로 추후 추가 예정)

  • Repository 코드만 포스팅 하겠습니다. 혹시 참조하실 분들은 상세 코드는 아래 이슈를 참조해주세요

  • 구현 방식

    • 레포지토리에서 최근 15개의 답변만 가져온다.
      • 저자님의 사이트에서 최근 15개만 가져오는 것을 확인
    • 뷰에서 뿌려준다.
  • 최근 답변 페이지

    • 네브바에 바로갈 수 있도록 추가 및 뷰 구성
    • 최근 15개의 답변 표기, (질문명)(답변내용)
    • 내용이 10글자를 초과한다면 10번째 글자 이후를 ...으로 표기
  • 최근 답변 가져오기

    • JPA findTop함수를 사용하였습니다.
    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>
  • 상세 코드를 확인하고 싶은 분들은 Git-PR를 참조해주세요.
profile
비슷한 어려움을 겪는 누군가에게 도움이 되길

0개의 댓글