Hibernate-validator Groups with Spring MVC

前端 未结 3 1076
慢半拍i
慢半拍i 2020-12-20 03:42

I\'m using hibernate-validator 4.3.1 and Spring MVC 3.2.3.

My application has a bean with the following properties and annotations (I\'ve removed most of them to mak

相关标签:
3条回答
  • 2020-12-20 03:45

    There is no more elegant way. Validating without specifying a group will validate the default groups. Hence you have to add it as described. The only other alternative is to explicitly validate all groups you are interested in via @Validated({GroupOne.class, GroupTwo.class}). I guess it is a matter of taste what you prefer.

    0 讨论(0)
  • 2020-12-20 03:48

    You can use @Valid:

    public ModelAndView myMethod(@ModelAttribute @Valid MyDto myDto, BindingResult result){
    
      if(result.hasErrors()){
        ....
    }
    
    0 讨论(0)
  • 2020-12-20 03:56

    if you extend your Group Interface with Default, it should take care of itself.

    Like

    public interface Group1 extends Default {}
    
    0 讨论(0)
提交回复
热议问题