@RequestMapping( value = {"/updatesto/{id}"}, method = {RequestMethod.POST}) public ModelAndView updatesto( @PathVariable Long id, @ModelAttribute("sto") Sto sto, BindingResult bindingResult, Model model, HttpSession session, Authentication auth) { ModelAndView mav = new ModelAndView(); rentValidator.validate(sto, bindingResult); if (bindingResult.hasErrors()) { logger.info("Returning updatesto.jsp page"); UserPrincipal user = userService.getUserByName(auth.getName()); mav.addObject("user", user); mav.addObject("sto", directorService.getStoById(id)); mav.setViewName("director.updatesto"); return mav; } Sto sto1 = directorService.getStoById(id); sto1.setName(sto.getName()); sto1.setPrice(sto.getPrice()); directorService.addSto(sto1); mav.setViewName("redirect:/home"); return mav; }
@RequestMapping( value = {"/addsto"}, method = {RequestMethod.POST}) public ModelAndView addsto( @ModelAttribute("sto") Sto sto, BindingResult bindingResult, Model model, HttpSession session, Authentication auth) { ModelAndView mav = new ModelAndView(); stoValidator.validate(sto, bindingResult); if (bindingResult.hasErrors()) { UserPrincipal user = userService.getUserByName(auth.getName()); mav.addObject("user", user); logger.info("Returning addsto.jsp page"); mav.setViewName("director.addsto"); return mav; } sto.setRating((float) 0); directorService.addSto(sto); mav.setViewName("redirect:/home"); return mav; }