我通过剖析示例应用程序来自学 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";
}
在告诉 eclipse 运行为...再次在服务器上运行后,我仍然收到相同的错误消息。
有什么我不明白的吗?