Inflearn brand logo image

Inflearn Community Q&A

tjdgh03125269's profile image
tjdgh03125269

asked

Real-world! Spring Boot and JPA Utilization 1 - Web Application Development

Change Detection and Merge

updateitem dto관련

Resolved

Written on

·

232

0

UpdateItemDto dto이렇게만들어서 사용해도된다고해서 만들어볼려고한느데
ItemService 에
@Transactional public void updateItem(Long itemId, UpdateItemDto dto) { Item findItem = itemRepository.findOne(itemId); findItem.setPrice(dto.getPrice()); findItem.setName(dto.getName()); findItem.setStockQuantity(dto.getStockQuantity()); }
이렇게 만들고
UpdateItemDto
 
@Getter
@Setter
public class UpdateItemDto {
private String name;
private int price;
private int stockQuantity;
 
}

 

 

이렇게만들고

근데 controller에서

@PostMapping("items/{itemid}/edit") public String updateItem(@PathVariable Long itemId, @ModelAttribute("form") BookForm form) {   itemService.updateItem(itemId, form); return "redirect:/items";

이런식으로되어있는데 form을어떻게dto로넘길수있을까요 controller에서 dto로넘기는건 안좋다고 다른질문에서본거같은데

spring-boot웹앱JPAspringjava

Answer 1

0

안녕하세요. 성호님, 공식 서포터즈 y2gcoder입니다.

쉽게 생각하시면 됩니다. service에 넘겨주기 전에 controller 에서 form 객체를 dto 객체로 변환해주시면 됩니다 :)


감사합니다.

tjdgh03125269's profile image
tjdgh03125269

asked

Ask a question