@RequestMapping("/list") public ModelAndView list() { ModelAndView mav = new ModelAndView("admin/product/list"); mav.addObject("products", productService.findAll()); return mav; }
@RequestMapping(value = "/modify", method = RequestMethod.GET) public ModelAndView goModify(@RequestParam long productId, Product product) { ModelAndView mav = new ModelAndView("admin/product/edit"); product = productService.getProductById(productId); mav.addObject("product", product); mav.addObject("productCategories", productCategoryService.findAll()); return mav; }
@RequestMapping(value = "/add", method = RequestMethod.POST) public String doAdd(@Valid Product product, BindingResult result, HttpServletRequest request) throws IllegalStateException, IOException { if (result.hasErrors()) { return "admin/product/edit"; } User user = (User) request.getSession().getAttribute("user"); product.setIcon(uploadFile(product.getFile())); productService.createNewProduct(product, user); return "redirect:/admin/product/list"; }
@RequestMapping(value = "/modify", method = RequestMethod.POST) public String doModify(@Valid Product product, BindingResult result, HttpServletRequest request) throws IllegalStateException, IOException { if (result.hasErrors()) { return "admin/product/edit"; } User user = (User) request.getSession().getAttribute("user"); String icon = uploadFile(product.getFile()); if (Validator.isNotNull(icon)) { product.setIcon(icon); } productService.updateProduct(product, user); FileUtil.rmdir( servletContext.getRealPath("/") + "/static/product_detail/" + product.getId() + ".shtml"); return "redirect:/admin/product/list"; }