Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @Autowired
- ProductService productService;
- @GetMapping({"/", "/home"})
- public String home() {
- return "index";
- }
- @GetMapping("/products")
- public String getAllProduct(Model model) {
- model.addAttribute("productList", productService.getAllProduct());
- return "products";
- }
- @GetMapping("/products/add")
- public String addProductGet(Model model) {
- model.addAttribute("product", new Product());
- return "productInfo";
- }
- @PostMapping("/products/add")
- public String addProductPost(@Valid Product product , Errors errors) {
- if (null != errors && errors.getErrorCount() > 0) {
- productService.addProduct(product);
- return "productInfo";
- } else {
- return "redirect:/products";
- }
- }
- @GetMapping("/products/edit/{code}")
- public String editProductGet(Model model, @PathVariable String code) {
- Product product = productService.getProductByCode(code);
- model.addAttribute("product", product);
- return "productInfo";
- }
- @PostMapping("/products/edit/{code}")
- public String editProductPost(@PathVariable String code, @ModelAttribute Product product) {
- productService.updateProduct(product, code);
- return "redirect:/products";
- }
- @GetMapping("/products/delete/{code}")
- public String deleteProduct(@PathVariable String code) {
- productService.deleteProduct(code);
- return "redirect:/products";
- }
- @GetMapping("/products/deleteConfirm/{code}")
- public String deleteConfirm(Model model, @PathVariable String code) {
- model.addAttribute("product", productService.getProductByCode(code));
- return "deleteConfirm";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement