Errors/BindingResult 参数应紧跟在模型属性、@RequestBody或@RequestPart参数之后声明
我正在通过剖析示例应用程序来自学Spring,然后在这里和那里添加代码来测试我在解剖过程中开发的理论。在测试我添加到Spring应用程序的一些代码时,我收到以下错误消息:
An Errors/BindingResult argument is expected to be declared immediately after the
model attribute, the @RequestBody or the @RequestPart arguments to which they apply
错误消息引用的方法为:
@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";
}
当我尝试在 Web 浏览器中加载 /catowners url 模式时,触发了此错误消息。我已经查看了此页面和此帖子,但解释似乎不清楚。
任何人都可以告诉我如何修复此错误,并解释它的含义吗?
编辑:
根据Biju Kunjummen的回应,我将语法更改为以下内容:
@RequestMapping(value = "/catowners", method = RequestMethod.GET)
public String findOwnersOfPetType(@Valid Integer typeID, BindingResult result, Map<String, Object> model)
我仍然收到相同的错误消息。难道是我不理解的东西吗?
第二次编辑:
根据Sotirios的评论,我将代码更改为以下内容:
@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";
}
在告诉日食运行为...再次在服务器上运行。
有什么我不明白的吗?