Closed coderclcl closed 1 year ago
@coderclcl 음 그냥 List<> 로 반환하고 idx 0 꺼내면 어떨까요 ?
맞는 방법인지는 모르겠지만,, 이렇게 시도해봐도 에러가 발생하네요 ㅜㅜ findFirstByPostByOrderByCreatedAtDesc(post) findByPostFirstByOrderByCreatedAtDesc(post) list 에서 하나 가져오는 방식으로 해결하겠습니다 ㅎㅎ
@coderclcl 엇 근데
findAllByPostOrderByCreatedAtDesc(post)
이거 List로 나오면 그중 첫번째꺼 꺼내야 베스트 댓글 꺼내게 되는 거 아닌가요?-?
@JH-Yoo 흑 저 링크에도 where 절이랑 같이 쓰인 FirstOrderBy나 TopOrderBy가 없네요 ㅜㅜ @yejipractice 앗 그렇네요..!! 제가 가져온 건 가장 오래된 댓글이군요...!!! 제안해주신 방법으로 변경했습니다! 감사해요~
@coderclcl 고생하셨습니다 👍 LGTM 😄
개요 ✋
피드 API 구현
작업사항 🗒️
가장 최근 댓글 하나만 보여주는 피드용 Dto를 만들었습니다. (PostInFeedResponseDto)
도움이 필요한 부분 :sos:
JPA로 where 절과 limit 절을 함께 하는 방법이 무엇일까요..?
limit 절만 사용하는 방법 findFirstByOrderByCreatedAtDesc()
where 절만 사용하는 방법 findByPost(post)
여기까지는 잘 동작하는데 아래처럼 where & limit 함께 사용하니 에러가 발생하네요.. findFirstByPostOrderByCreatedAtDesc(post)
혹시 아는 분 계시면 조언 부탁드립니다! 제가 참고한 자료는 Spring Data JPA - Limiting Query Results 입니다