@Controller
public class EmployeeController {
@Autowired
EmployeeDao employeeDao;
@Autowired
DepartmentDao departmentDao;
@GetMapping("/employees")
public String index(Model model) {
Collection<Employee> employees = employeeDao.index();
model.addAttribute("employees", employees);
return "employees/index";
}
@PostMapping("/employees")
public String store(Employee employee) {
employeeDao.store(employee);
return "redirect:/employees";
}
@GetMapping("/employees/{id}")
public String show(@PathVariable("id") Integer id, Model model) {
Employee employee = employeeDao.show(id);
model.addAttribute("employee", employee);
Collection<Department> departments = departmentDao.index();
model.addAttribute("departments", departments);
return "employees/show";
}
@PutMapping("/employees/{id}")
public String update(@PathVariable("id") Integer id, Employee employee) {
employee.setId(id);
employeeDao.update(employee);
return "redirect:/employees";
}
@DeleteMapping("/employees/{id}")
public String destroy(@PathVariable("id") Integer id) {
employeeDao.destroy(id);
return "redirect:/employees";
}
}