jjzjj

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

coder 2024-03-12 原文

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

@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

没有使用 javax.validation.constraints.Min.List

所以目前这看起来像是规范错误?!?

最佳答案

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

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

关于Java Bean 验证 : How do I specify multiple validation constraints of the same type but with different groups?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29502058/

有关Java Bean 验证 : How do I specify multiple validation constraints of the same type but with different groups?的更多相关文章

随机推荐