Search code examples
springspring-mvcmodel-view-controllerhttp-status-code-400

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


This is my controller

@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";

 }

and my bean is

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

The form is validated when i give the name of between 5 and 45 characters. But when the form is not validated I am getting 400 status error report. I dont know why i am getting the error. Please need help here


Solution

  • BindingResult parameter must follow the parameter being validated immediately. It's described here: 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).