// saveOrUpdate or update page @RequestMapping(value = "/admin/employees", method = RequestMethod.POST) public String saveOrUpdateEmployee( @ModelAttribute("employeeForm") @Validated EmployeeForm employeeForm, BindingResult result, final RedirectAttributes redirectAttributes, Model model) { if (result.hasErrors()) { populateDefaultModel(model); return "admin/employeeForm"; } else { redirectAttributes.addFlashAttribute("css", "success"); if (employeeForm.isNew()) { redirectAttributes.addFlashAttribute("msg", "Employee added successfully!"); } else { redirectAttributes.addFlashAttribute("msg", "Employee updated successfully!"); } Employee employee; employee = convertEmployeeFormToEmployee(employeeForm); employeeServiceDao.saveOrUpdate(employee); return "redirect:/admin/employees/" + employee.getId(); } }
private void populateEmployeeForm(EmployeeForm employeeForm, Employee employee) { employeeForm.setId(employee.getId()); employeeForm.setName(employee.getName()); employeeForm.setSurname(employee.getSurname()); employeeForm.setPhoneNumber(employee.getPhoneNumber()); employeeForm.setDateOfBirth(employee.getDateOfBirth()); employeeForm.setPosition(employee.getPosition()); employeeForm.setSalary(employee.getSalary()); }