예제 #1
0
  // 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();
    }
  }
예제 #2
0
 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());
 }