728x90
9.웹 계층 개발 2(주문)
- 목차
- 1.상품 주문
- 2.주문목록 검색, 취소
1.상품 주문
OrderController
@Controller
@RequiredArgsConstructor
public class OrderController {
private final OrderService orderService;
private final MemberService memberService;
private final ItemService itemService;
@GetMapping("/order")
public String createForm(Model model){
List<Member> members = memberService.findMembers();
List<Item> items = itemService.findItems();
model.addAttribute("members",members);
model.addAttribute("items",items);
return "order/orderForm";
}
@PostMapping("/order")
public String order(@RequestParam("memberId") Long memberId,
@RequestParam("itemId") Long itemId,
@RequestParam("count") int count){
orderService.order(memberId,itemId,count);
return "redirect:/orders";
}
}
2.주문목록 검색, 취소
OrderController
@Controller
@RequiredArgsConstructor
public class OrderController {
private final OrderService orderService;
private final MemberService memberService;
private final ItemService itemService;
@GetMapping("/orders")
public String orderList(@ModelAttribute("orderSearch") OrderSearch orderSearch, Model model){
List<Order> orders = orderService.findOrders(orderSearch);
model.addAttribute("orders",orders);
return "order/orderList";
}
@PostMapping("/orders/{orderId}/cancel")
public String cancelOrder(@PathVariable("orderId")Long orderId){
orderService.cancelOrder(orderId);
return "redirect:/orders";
}
}
참고자료
https://www.inflearn.com/course/%EC%8A%A4%ED%94%84%EB%A7%81%EB%B6%80%ED%8A%B8-JPA-%ED%99%9C%EC%9A%A9-1/dashboard (웹 애플리케이션개발)
728x90
'Back-End > Spring Data' 카테고리의 다른 글
2.JPA 시작하기 (0) | 2021.01.04 |
---|---|
1.JPA 소개 (0) | 2021.01.04 |
8.변경감지 와 병합 (0) | 2021.01.01 |
7.웹 계층 개발 1(회원,상품) (0) | 2021.01.01 |
6.주문도메인개발 (0) | 2020.12.30 |