@RequestMapping(value = "/leavepolicy/admin/create", method = RequestMethod.POST) public String create(LeavePolicy leavePolicy, BindingResult result) { if (result.hasErrors()) { return "leavepolicy/create"; } leavePolicy = service.create(leavePolicy); Set<User> userList = userService.findAll(); for (User user : userList) { UserLeavePolicy ulp = new UserLeavePolicy(); ulp.setUser(user); ulp.setLeavePolicy(leavePolicy); ulpService.create(ulp); } return "redirect:/leavepolicy"; }
@RequestMapping(value = "/leavepolicy/admin/update", method = RequestMethod.POST) public String update(LeavePolicy leavePolicy, BindingResult result) { if (result.hasErrors()) { return "leavepolicy/edit"; } service.update(leavePolicy); return "redirect:/leavepolicy"; }
@RequestMapping(value = "/leavepolicy/admin/edit/{id}", method = RequestMethod.GET) public String getCreateForm(@PathVariable Long id, Model model) { DetachedCriteria dc = DetachedCriteria.forClass(LeavePolicy.class); dc.add(Restrictions.idEq(id)); LeavePolicy lp = service.get(dc); model.addAttribute("leavePolicy", lp); return "leavepolicy/edit"; }
@RequestMapping(value = "/leavepolicy", method = RequestMethod.GET) public String list(Model model) { Set<LeavePolicy> holidays = service.findAll(); String jsonData = ""; try { jsonData = mapper.writeValueAsString(holidays); } catch (Exception e) { e.printStackTrace(); } model.addAttribute("leavePolicyJsonData", jsonData); return "leavepolicy/list"; }