コード例 #1
0
 /*
  * 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";
 }
コード例 #2
0
 /*
  * 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();
 }
コード例 #3
0
  @RequestMapping(
      value = {"/", "/list"},
      method = RequestMethod.GET,
      headers = "Accept=application/json")
  public Employee listEmployees() {

    List<Employee> employees = service.findAllEmployees();
    return employees.get(0);
  }
コード例 #4
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";
  }