Skip to content

Conversation

@CheorHyeon
Copy link
Owner

@CheorHyeon CheorHyeon commented Aug 4, 2023

점프투스프링부트 3-15 추가기능

일곱번째로 답변 페이징, 정렬 기능을 구현했습니다.

  • src/main/java/com/ll/spring_additional/base/initData/NotProd.java

    • JDBC 배치쓰기를 적용하기 위해 리스트를 활용하였고, 초기 데이터 초기화 속도 증가 시켰습니다.
  • src/main/java/com/ll/spring_additional/boundedContext/answer/repository/AnswerRepository.java

    • findAllByQuestion 메서드를 통해 페이지에 해당하는 수만 가져옵니다.
    • findAllByQuestionOrderByVoter 메서드를 통해 추천 수에 따라 정렬해서 가져옵니다(List<Sort.Order> sorts 에는 속성만 들어갈 수 있어 별도의 JPQL이나 QueryDsl이 필요합니다.)
  • src/main/java/com/ll/spring_additional/boundedContext/answer/service/AnswerService.java

    • getAnswerPage 메서드를 통해 sort값에 따른 분기를 진행합니다. "return answerRepository.findAllByQuestion(question, pageable);" 코드가 중복되는데, 추후 switch문 도입 등 개선이 필요합니다.
  • src/main/resources/templates/question/question_detail.html

    • 현재 있는 페이지 번호는 paging.number로 알 수 있어 정렬 시 기준을 적용 시킬 수 있습니다.
    • param.sort로 페이지 이동 전 파라미터로 sort 값을 가져와 페이지 이동 버튼에 넣어놨기에, 페이지 이동 시 정렬 조건이 유지됩니다

Close #14

@CheorHyeon CheorHyeon added the enhancement New feature or request label Aug 4, 2023
@CheorHyeon CheorHyeon self-assigned this Aug 4, 2023
@CheorHyeon CheorHyeon merged commit 59a5dfd into main Aug 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

추가 기능 7) 답변 페이징 및 정렬

2 participants