Java Bean Validation: How do I specify multiple validation constraints of the same type but with different groups?

你离开我真会死。 提交于 2019-12-30 17:35:31

问题


I have multiple processes in which the bean properties must have different values. Example:

@Min( value=0, groups=ProcessA.class )
@Min( value=20, groups=ProcessB.class )
private int temperature;

Unfortunately the bean validation JSR 303 has not set @Repeatable on javax.validation.constraints.Min so this approach does not work. I found "Min.List" but without any doc about how to use it. Instead the official Oracle doc states at http://docs.oracle.com/javaee/7/api/javax/validation/constraints/class-use/Min.List.html

No usage of javax.validation.constraints.Min.List

So at moment this looks like a specification error?!?


回答1:


The syntax for Min.List, as for any other annotation taking an array of annotations as one of its attributes, is

@Min.List({ @Min(value = 0, groups = ProcessA.class),
            @Min(value = 20, groups = ProcessB.class) })


来源:https://stackoverflow.com/questions/29502058/java-bean-validation-how-do-i-specify-multiple-validation-constraints-of-the-sa

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