본문 바로가기
Spring boot

Spring boot ( 댓글 목록 불러오기)

by z00h 2021. 10. 8.

board의 id에 따른 댓글 목록 불러오기

 

처음에는 comment의 댓글 목록을 그냥 불러오는 코드를 작성하였으나

board의 id에 맞는 comment목록을 불러오는 코드로 바꿔서 만들어 보았다.

 

 

불러오기 때문에 getmapping으로 처리.

board id에 따른 댓글목록 getCommentsByBoardId 매소드 만들고 commentServiced로 반환.

 

CommentController.java

 

 

 

 

 

마찬가지로 ApiResponse로 받아와 성공적으로 실행이 되면 "success to get comments by board id" 을 보여줌

 

CommentService.java

 

 

 

 

CommentDAO.java에서 comment의 list를 불러옴

 

List<CommentDTO> getCommentsByBoardId(int boardId);

 

 

 

 

 

 

쿼리문에서 board의 Id값에 따른 값이기 때문에 where절 사용

 

CommentMapper.xml

 

 

 

 

확인해본 결과

 

 

board의 id값이 2인 comment의 list를 불러오기 성공!