How do I use @Valid with Spring MVC's @RequestBody parameters?

前端 未结 2 1608
孤城傲影
孤城傲影 2020-12-31 01:14

I\'m having an issue with using @Valid on a parameter to a handler method on my @Controller. My code looks like this:

@RequestMappi         


        
相关标签:
2条回答
  • 2020-12-31 01:51

    Are you using Spring 3.1? It is a newly added feature in Spring version 3.1. Please see Validation For @RequestBody Method Arguments

    0 讨论(0)
  • 2020-12-31 01:51

    This is an issue in spring 3.0 and it is fixed in 3.1 M2.

    https://jira.springsource.org/browse/SPR-6709

    If you are using spring 3.0, based on some threads and extensive reading, here is the best approach for this problem. An aspect oriented approach so that we can back out when you upgrade it to the version of spring which fixes this issue.

    An aspect which intercepts calls to method which uses @RequestMapping annotation and for each parameter which has @Valid annotation on it, call the corresponding validator in the aspect.

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