Java
변수의 종류와 변수 이름
Java) 선언 위치에 따른 변수의 종류와 변수 이름 작성
선언 위치에 따른 변수의 종류 전역변수 클래스 내 어디서든 호출하여 사용할 수 있는 변수 초기화를 하지 않을 시 자동으로 0으로 초기화 전역변수의 종류 객체(인스턴스) 변수 클래스 영역에
ik0501.tistory.com
Spring
댓글 좋아요 기능 구현
좋아요를 할떄마다 update했었던 방식에서 count를 통해 필요할때만 불러오게 변경
@Transactional
public MemoResponseDto openMemo(Long id) {
Memo memo = memoRepository.findById(id).orElseThrow(
() -> new RequestException(ErrorCode.게시글이_존재하지_않습니다_400)
);
List<CommentDto> commentDtoList = new ArrayList<>();
for (Comment comment : memo.getCommentList()) {
commentDtoList.add(new CommentDto(comment,commentLikeRepository.countAllByCommentId(comment.getId())));
}
return new MemoResponseDto(memo, commentDtoList);
}
게시글을 조회할 때만 count하여 값 넘겨주기
'TIL(Today Ingwang Learned)' 카테고리의 다른 글
TIL) 2022 - 12 - 14(Sping,GIT) (1) | 2022.12.15 |
---|---|
TIL) 2022 - 12 - 13(Sping) (0) | 2022.12.14 |
TIL)2022 - 12 - 10(Spring) (2) | 2022.12.11 |
TIL)2022 - 12 - 09(Spring) (0) | 2022.12.10 |
TIL)2022-12-08(Spring) (0) | 2022.12.09 |