인프런 커뮤니티 질문&답변
Entity와 dto
작성
·
513
0
안녕하세요! jpa 지식이 얕아 질문드립니다.
유저의 주문 리스트를 뽑아올 때, 아래와 같이 서비스 클래스에서 userId를 이용해 먼저 레포 호출해서 엔티티를 만들고, 이 만든 엔티티를 모델매퍼로 다시 Dto로 바꾸지 않습니까?
왜 엔티티를 먼저 만들었다가 Dto로 바꾸는지 이유가 궁금합니다.
Dto와 Entity의 각각의 존재 의의와 목적은 무엇인가요?
public UserDto getUserByUserId(String userId) { UserEntity userEntity = userRepository.findByUserId(userId); if (userEntity == null) throw new UsernameNotFoundException("User not found"); UserDto userDto = new ModelMapper().map(userEntity, UserDto.class); List<ResponseOrder> ordersList = orderServiceClient.getOrders(userId); userDto.setOrders(ordersList); return userDto; }
답변 1
0
안녕하세요, 이도원입니다.
문의하신 질문에 대해서는 이전에도 DTO, Entity 관련해서 비슷하게 질문된 내용이 있어서 참고할 만한 게시물을 알려드립니다.
https://www.inflearn.com/questions/333140 https://www.inflearn.com/questions/595852 https://www.inflearn.com/questions/603965
혹시 추가적인 궁금하신 사항이 있으시면 다시 글 남겨주세요.
감사합니다.





