[ 상황 ]
댓글 기능이 있는 게시글을 구현했는데,
게시글에 댓글이 없으면 게시글 조회가 안됐다.
[ 해결 ]
게시글 조회 시 댓글이 없어도 에러가 안나게,
게시글 조회 service에 if로 예외처리를 해줬다.
public 게시글DTO readService(int idx) {
Set<RcommentDTO> rcommentDTOSet = new HashSet<>();
result.forEach(arr->{
Rcomment rcomment = (Rcomment) arr[3];
if (rcomment!= null) {
RcommentDTO rcommentDTO = RcommentDTO.builder()
.idx(rcomment.getIdx())
.writer(rcomment.getWriter())
.contents(rcomment.getContents())
.build();
rcommentDTOSet.add(rcommentDTO);
}
});
}
해결!