TIL(Today Ingwang Learned)

2022 - 12- 12(Spring , Java)

김코식 2022. 12. 13. 04:42

 


Java

변수의 종류와 변수 이름

https://ik0501.tistory.com/entry/Java-%EC%84%A0%EC%96%B8-%EC%9C%84%EC%B9%98%EC%97%90-%EB%94%B0%EB%A5%B8-%EB%B3%80%EC%88%98%EC%9D%98-%EC%A2%85%EB%A5%98%EC%99%80-%EB%B3%80%EC%88%98-%EC%9D%B4%EB%A6%84-%EC%9E%91%EC%84%B1

 

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하여 값 넘겨주기