DTO관련 질문드립니다.
258
작성자 없음
// Controller
@PostMapping("items/{itemId}/edit")
public String updateItem(@PathVariable("itemId") Long itemId, @ModelAttribute("form") BookForm form) {
itemService.updateItem(new UpdateItemDto(form));
return "redirect:/items";
}
// Entity
@Entity
@DiscriminatorValue("B")
@Getter @Setter
public class Book extends Item {
private String author;
private String isbn;
public void updateBook(UpdateItemDto updateItemDto) {
this.author = updateItemDto.getAuthor();
this.isbn = updateItemDto.getIsbn();
this.setId(updateItemDto.getId());
this.setName(updateItemDto.getName());
this.setPrice(updateItemDto.getPrice());
this.setStockQuantity(updateItemDto.getStockQuantity());
}
}
// Service
@Transactional
public void updateItem(UpdateItemDto updateItemDto) {
Book foundedItem = (Book) itemRepository.findOne(updateItemDto.getId());
foundedItem.updateBook(updateItemDto);
}
선생님 양질의 강의 잘보고있습니다.
엔티티에서 북이 아이템을 상속하고있는데
그 상속하는 필드에 값을 변경시 위의 코드와 같이 셋터를 불러서 값을 변경시켜주면될까요? 아니면
아이템에도 별도의 메소드를 생성하여 값을 변경해주는게 좋은가요?
답변 1
setter 사용하지 않기
0
46
1
안녕하세요 치킨 디도스 이벤트 보고 흉내내보려 들어왔습니다..
0
56
2
OrderServiceTest 상문주문 테스트 시 update 쿼리 문의
0
55
1
sdk 설정 오류
0
105
2
오탈자 - @Transactional
0
92
1
src/test/resources 테스트 경로 문제
0
93
1
상품 등록후 H2 db 출력 순서 바꿀 수 있나요?
0
82
1
MemberRepositoryTest 실행오류
0
127
1
boot 4.x >>> trasasction rolled back log & p6spy(영한님, 수업 자료 업데이트 해주시면 감사하겠습니다!!)
1
228
2
강의 마지막 QueryDSL 사용 부분 질문있습니다
1
186
2
클라이언트에서 isbn과 author 수정 요청을 한 경우에 대해 질문드립니다.
0
73
1
도메인 모델 패턴 vs 트랜잭션 스크립트 패턴
0
112
1
기본 생성자
0
83
1
h2 DB 연결시 jdbc url 변경 이유가 궁금합니다.
0
130
1
멤버서비스테스트 부분에서 막힙니다.
0
214
4
실무에서도 EntityManager를 이용해서 많이 작업하는 편일까요?
0
153
1
초반에 h2 다운로드 과정 꼭 필요한가요?
0
164
2
자신 필드에도 get으로 접근하는 이유가 있을까요?
0
145
1
24분 27초 연관관계 편의 메서드 위치
0
134
1
단건 주문만 가능하게 한건 의도한 부분이신가요?
0
135
2
빌드 툴, Gradle
0
89
1
h2연결은 된 것 같은데 엔티티 테이블까지 작성 후 확인해보아도 테이블이 안보입니다
0
89
2
Repository에서 EntityManager 주입 방식 차이
0
114
1
롬복과 사용자 정의 setter 메서드
0
86
1





