I am trying to validate both header and body of a post request using the below code
@PostMapping(path = "/shelloo", consumes = "application/json")
public String ssfirst(@Valid @RequestHeader("username") String username, BindingResult headerBindingResult,
@ModelAttribute RequestBodyModel requestBodyModel, BindingResult bodyBindingResult) {
if (headerBindingResult.hasErrors())
System.out.println("found header error");
else if (bodyBindingResult.hasErrors())
System.out.println("found body error");
else
System.out.println("else Print");
return "sample response";
}
I am getting Exception as follow
java.lang.IllegalStateException: An Errors/BindingResult argument is expected to be declared immediately after the model attribute, the @RequestBody or the @RequestPart arguments to which they apply: public java.lang.String com.jvr.middlewareuat.rest.MainController.ssfirst(java.lang.String,org.springframework.validation.BindingResult,com.jvr.middlewareuat.model.RequestBodyModel,org.springframework.validation.BindingResult)