Java Bean验证:如何指定相同类型但具有不同组的多个验证约束? [英] Java Bean Validation: How do I specify multiple validation constraints of the same type but with different groups?

查看:106
本文介绍了Java Bean验证:如何指定相同类型但具有不同组的多个验证约束?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有多个进程,其中Bean属性必须具有不同的值.示例:

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;

不幸的是,bean验证JSR 303尚未设置@Repeatable 在javax.validation.constraints.Min上,因此该方法不起作用. 我找到了"Min.List",但没有有关如何使用它的任何文档.相反,Oracle官方文档在 http://docs.oracle.com/javaee/7/api/javax/validation/constraints/class-use/Min.List.html

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

不使用javax.validation.constraints.Min.List

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

所以现在这看起来像是规范错误?!?

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

推荐答案

对于Min.List的语法,与将注释数组作为其属性之一的任何其他注释一样,是

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) })

这篇关于Java Bean验证:如何指定相同类型但具有不同组的多个验证约束?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆