Exemplo n.º 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:/";
  }
Exemplo n.º 2
0
  @RequestMapping("/")
  public String home(Model model) {

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

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