Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,8 @@
@Controller
public class StudentController {

@Autowired
private StudentService studentService;

public StudentController(StudentService studentService) {
super();
this.studentService = studentService;
}

// handler method to handle list students and return mode and view
@GetMapping("/students")
Expand Down Expand Up @@ -48,23 +44,6 @@ public String editStudentForm(@PathVariable Long id, Model model) {
model.addAttribute("student", studentService.getStudentById(id));
return "edit_student";
}

@PostMapping("/students/{id}")
public String updateStudent(@PathVariable Long id,
@ModelAttribute("student") Student student,
Model model) {

// get student from database by id
Student existingStudent = studentService.getStudentById(id);
existingStudent.setId(id);
existingStudent.setFirstName(student.getFirstName());
existingStudent.setLastName(student.getLastName());
existingStudent.setEmail(student.getEmail());

// save updated student object
studentService.updateStudent(existingStudent);
return "redirect:/students";
}

// handler method to handle delete student request

Expand Down