@RequestMapping(value = "/employees/delete/{employeeId}", method = RequestMethod.POST) public String deleteEmployee(@PathVariable("employeeId") Long employeeId, HttpSession session) { if (employeeService.deleteEmployee(employeeId)) { FlashMessage.createSuccessMessage(session, "employees.delete.success", employeeId); } else { FlashMessage.createErrorMessage(session, "employees.delete.error", employeeId); } return "redirect:/employees/"; }
@RequestMapping(value = "/employees/add", method = RequestMethod.POST) public String addEmployee( @ModelAttribute("employee") @Valid EmployeeForm employeeForm, BindingResult result, ModelMap model, HttpSession session) { if (result.hasErrors()) { FlashMessage.createErrorMessage( session, "employees.add.error", employeeForm.getLastName(), employeeForm.getFirstName()); return listEmployees(employeeForm, model, session); } employeeService.addEmployee(employeeForm); FlashMessage.createSuccessMessage( session, "employees.add.success", employeeForm.getLastName(), employeeForm.getFirstName()); return "redirect:/employees/"; }
@RequestMapping(value = "/employees/", method = RequestMethod.GET) public String listEmployees( @ModelAttribute("employee") EmployeeForm employeeForm, ModelMap model, HttpSession session) { List<Department> departments = departmentService.listDepartments(); if (departments.isEmpty()) { FlashMessage.createInfoMessage(session, "employees.empty.departments"); } model.addAttribute("employee", employeeForm); model.addAttribute("departments", departments); model.addAttribute("employees", employeeService.listEmployees()); return "employees"; }