Spring3 doesn't work @valid when json request I got 400 Bad Request error

前端 未结 1 443
执笔经年
执笔经年 2021-01-25 12:43

I\'m using Spring3 framework ,hibernate validator and jackson.

when I request for jsondata to server. returned 400 Bad Request error.

then my data is missmatch t

相关标签:
1条回答
  • 2021-01-25 13:15

    Data binding (mapping request to objects) is an independent process from data validation. In Spring, data binding can contribute with its own binding errors to overall validation errors.

    Binding errors are supported by Spring's standard WebDataBinder, which kicks in when the method parameter is annotated with @ModelAttribute

    With @RequestBody annotation a completely different mechanism is used - HttpMessageConverters (in you case probably the MappingJackson2HttpMessageConverter). When the JSON unmarshalling fails a HttpMessageNotReadableException exception is thrown.

    You can handle exceptions within your global HandlerExceptionResolver or a special @ExceptionHandler annotated handler method within the handler itself or a global @ControllerAdvice.

    0 讨论(0)
提交回复
热议问题