【发布时间】:2015-05-26 01:53:25
【问题描述】:
我有一个自定义注释约束,但我希望仅在另一个约束有效时才检查它。例如:
@NotNull
private String propertyA;
@Digits
private String propertyB;
如果 propertyA 为 null ,我不想检查 propertyB 上的“@Digits”。
我该如何解决这个问题?谢谢。
【问题讨论】:
标签: preconditions oval
我有一个自定义注释约束,但我希望仅在另一个约束有效时才检查它。例如:
@NotNull
private String propertyA;
@Digits
private String propertyB;
如果 propertyA 为 null ,我不想检查 propertyB 上的“@Digits”。
我该如何解决这个问题?谢谢。
【问题讨论】:
标签: preconditions oval
你可以使用“when”属性,例如
@NotNull
private String propertyA;
@Digits(when="groovy:_this.propertyA!=null")
private String propertyB;
此示例要求 Groovy 运行时位于类路径中。你也可以使用其他脚本语言,见http://oval.sourceforge.net/userguide.html#declaring-conditional-constraints
【讨论】: