Hibernate-validator Groups with Spring MVC

拈花ヽ惹草 提交于 2019-11-29 12:24:52

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.

You can use @Valid:

public ModelAndView myMethod(@ModelAttribute @Valid MyDto myDto, BindingResult result){

  if(result.hasErrors()){
    ....
}

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

Like

public interface Group1 extends Default {}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!