示例#1
0
  @RequestMapping(value = "/addEmployee", method = RequestMethod.POST)
  public String addEmployee(
      @ModelAttribute("newEmployee") @Valid Employee employee, BindingResult result) {

    if (result.hasErrors()) {
      return "employee";
    }

    if (employee.getId() == 0) {
      employeeDAO.save(employee);
    } else {
      employeeDAO.update(employee);
    }
    return "redirect:/";
  }
示例#2
0
  @RequestMapping("/")
  public String home(Model model) {

    model.addAttribute("employee", new Employee());
    List<Employee> empList = employeeDAO.getAll();
    model.addAttribute("employees", empList);
    return "home";
  }
示例#3
0
  @RequestMapping("/remove/{id}")
  public String removePerson(@PathVariable("id") int id) {

    employeeDAO.deleteById(id);
    return "redirect:/";
  }
示例#4
0
 @RequestMapping("/edit/{id}")
 public String editPerson(@PathVariable("id") int id, Model model) {
   model.addAttribute("newEmployee", employeeDAO.getById(id));
   return "employee";
 }