해결된 질문
작성
·
308
5
@Getter @Setter
public class UpdateBookDto {
private String name;
private int price;
private int stockQuantity;
private String author;
private String isbn;
public static UpdateBookDto updateBookAll(
String name, int price, int stockQuantity,
String author, String isbn) {
UpdateBookDto bookDto = new UpdateBookDto();
bookDto.name = name;
bookDto.price = price;
bookDto.stockQuantity = stockQuantity;
bookDto.author = author;
bookDto.isbn = isbn;
return bookDto;
}
}
public class ItemController {
@PostMapping("/{itemId}/edit")
public String updateItem(@PathVariable String itemId,
@ModelAttribute("form") BookForm form) {
UpdateBookDto bookDto = UpdateBookDto.updateBookAll(
form.getName(),
form.getPrice(),
form.getStockQuantity(),
form.getAuthor(),
form.getIsbn()
);
itemService.updateItem(form.getId(), bookDto);
return "redirect:/items";
}
}
public class ItemService {
@Transactional
public void updateItem(Long itemId, UpdateBookDto dto) {
Book findBook = (Book) itemRepository.findOne(itemId);
findBook.changeBook(
dto.getName(),
dto.getPrice(),
dto.getStockQuantity(),
dto.getAuthor(),
dto.getIsbn()
);
}
}
public class Book extends Item {
public void changeBook(String name, int price,
int stockQuantity, String author, String isbn) {
super.changeItem(name, price, stockQuantity);
this.author = author;
this.isbn = isbn;
}
}
안녕하세요 답변 감사합니다!