HTTP 状态 400 客户端发送的请求在语法上不正确

HTTP Status 400 The request sent by the client was syntactically incorrect

这是我的控制器

@RequestMapping("/offercreated")

 public String offerCreated(@Valid Offer offer, Model model, BindingResult  result) {

 if (result.hasErrors()) {

 return "createoffer";

 } else {

 System.out.println("form validated");

 return "offercreated";

 }

我的豆子是

@Size(min = 5, max = 45)
    private String name;

当我给出 5 到 45 个字符的名称时,表单被验证。但是当表单未经验证时,我收到 400 状态错误报告。我不知道为什么我会收到错误消息。请在这里需要帮助

哇,当我将控制器参数更改为模型,然后提供它的工作时!!

@RequestMapping("/offercreated")

public String offerCreated(Model 模型,@Valid Offer 报价,BindingResult 结果){

if (result.hasErrors()) {

return "createoffer";

}否则{

System.out.println("form validated");

return "offercreated";

}

有人可以解释这是为什么吗?我很困惑!

BindingResult 参数必须紧跟在正在验证的参数之后。此处描述:http://docs.spring.io/spring/docs/current/spring-framework-reference/html/mvc.html

org.springframework.validation.Errors / org.springframework.validation.BindingResult validation results for a preceding command or form object (the immediately preceding method argument).