Example #1
0
  @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";
  }
Example #2
0
  @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";
  }