프로젝트/SpringBoot Side Project

대댓글 JPA로 구현하기

amungstudy 2024. 1. 23. 13:36

Comment라는 엔티티를 부모와 자식 상속관계로 구현한다.

 

commentResponseDto.getCommentId() = 1
commentResponseDto.getContent() = 댓글1
commentResponseDto.getParentId() = null
child.getContent() = 답글1
commentResponseDto.getCommentId() = 2
commentResponseDto.getContent() = 답글1
commentResponseDto.getParentId() = 1
child.getContent() = 답글1의 답글1
commentResponseDto.getCommentId() = 3
commentResponseDto.getContent() = 답글1의 답글1
commentResponseDto.getParentId() = 2