본문 바로가기

TIL(Today Ingwang Learned)

2022 - 12- 12(Spring , Java)

 


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

'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


Calendar
«   2025/03   »
1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31
Tags
더보기
Archives
Visits
Today
Yesterday