I am teaching myself Spring by dissecting example applications and then adding code here and there to test theories that I develop during the dissection. I am getting the following error message when testing some code that I added to a Spring application:
An Errors/BindingResult argument is expected to be declared immediately after the
model attribute, the @RequestBody or the @RequestPart arguments to which they apply
The method to which the error message refers is:
@RequestMapping(value = "/catowners", method = RequestMethod.GET)
public String findOwnersOfPetType(Integer typeID, BindingResult result, Map<String, Object> model) {
// find owners of a specific type of pet
typeID = 1;//this is just a placeholder
Collection<Owner> results = this.clinicService.findOwnerByPetType(typeID);
model.put("selections", results);
return "owners/catowners";
}
This error message was triggered when I tried to load the /catowners url pattern in the web browser. I have reviewed this page and this posting, but the explanation does not seem clear.
Can anyone show me how to fix this error, and also explain what it means?
EDIT:
Based on Biju Kunjummen's response, I changed the syntax to the following:
@RequestMapping(value = "/catowners", method = RequestMethod.GET)
public String findOwnersOfPetType(@Valid Integer typeID, BindingResult result, Map<String, Object> model)
I am still getting the same error message. Is ther something I am not understanding?
SECOND EDIT:
Based on Sotirios's comment, I changed the code to the following:
@RequestMapping(value = "/catowners", method = RequestMethod.GET)
public String findOwnersOfPetType(BindingResult result, Map<String, Object> model) {
// find owners of a specific type of pet
Integer typeID = 1;//this is just a placeholder
Collection<Owner> results = this.clinicService.findOwnerByPetType(typeID);
model.put("selections", results);
return "owners/catowners";
}
I am still getting the same error message after telling eclipse to run as...run on server again.
Is there something that I am not understanding?