/* * This method will delete an employee by it's SSN value. */ @RequestMapping( value = {"/delete-{ssn}-employee"}, method = RequestMethod.GET) public String deleteEmployee(@PathVariable String ssn) { service.deleteEmployeeBySsn(ssn); return "redirect:/list"; }
/* * This method will list all existing employees. */ @RequestMapping("/hello") public List<Employee> hello( @RequestParam(value = "name", required = false, defaultValue = "World") String name, Model model) { model.addAttribute("name", name); return service.findAllEmployees(); }
@RequestMapping( value = {"/", "/list"}, method = RequestMethod.GET, headers = "Accept=application/json") public Employee listEmployees() { List<Employee> employees = service.findAllEmployees(); return employees.get(0); }
/* * This method will be called on form submission, handling POST request for * saving employee in database. It also validates the user input */ @RequestMapping( value = {"/new"}, method = RequestMethod.POST) public String saveEmployee(@Valid Employee employee, BindingResult result, ModelMap model) { if (result.hasErrors()) { return "registration"; } service.saveEmployee(employee); model.addAttribute("success", "Employee " + employee.getName() + " registered successfully"); return "success"; }