Exemplo n.º 1
0
  @RequestMapping(value = "/student.do", method = RequestMethod.POST)
  public String doActions(
      @ModelAttribute Student student,
      BindingResult result,
      @RequestParam String action,
      Map<String, Object> map) {

    Student studentResult = new Student();

    switch (action.toLowerCase()) {
      case "add":
        studentService.add(student);
        studentResult = student;
        break;
      case "edit":
        studentService.edit(student);
        studentResult = student;
        break;
      case "delete":
        studentService.delete(student.getStudentId());
        studentResult = new Student();
        break;
      case "search":
        Student searchStudent = studentService.getStudent(student.getStudentId());
        studentResult = searchStudent != null ? searchStudent : new Student();
    }
    map.put("student", studentResult);
    map.put("studentList", studentService.getAllStudents());
    return "student";
  }
Exemplo n.º 2
0
 @RequestMapping("/index")
 public String setupForm(Map<String, Object> map) {
   Student student = new Student();
   map.put("student", student);
   map.put("studentList", studentService.getAllStudents());
   return "student";
 }