I'm getting this error when I try to redirect to a certain view.
In one handler method i have:
// get student ID, add it to model, and return redirect URI
Integer studentId = student.getStudentId();
model.addAttribute("studentId", studentId);
return "redirect:/students/{studentId}";
But I'm not getting the parameter studentId
in this handler method:
@RequestMapping(value="/{student}", method = RequestMethod.GET)
public String getStudent(@PathVariable Integer studentId, Model model) {
Student student = studentService.get(studentId);
model.addAttribute("student", student);
return "student";
}
What am I missing here?
If you don't specify the name of the path variable, Spring tries to use the name of your parameter.
Therefore in
@RequestMapping(value="/{student}", method = RequestMethod.GET)
public String getStudent(@PathVariable Integer studentId, Model model) {
Spring will try to find a path variable called studentId
while you have a path variable called student
.
Just add a value attribute
@PathVariable("student") Integer studentId
or change the parameter name.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With