【问题标题】:How to set priority of custom Oval constraint如何设置自定义椭圆约束的优先级
【发布时间】:2015-05-26 01:53:25
【问题描述】:

我有一个自定义注释约束,但我希望仅在另一个约束有效时才检查它。例如:

@NotNull
private String propertyA;
@Digits
private String propertyB;

如果 propertyA 为 null ,我不想检查 propertyB 上的“@Digits”。

我该如何解决这个问题?谢谢。

【问题讨论】:

    标签: preconditions oval


    【解决方案1】:

    你可以使用“when”属性,例如

    @NotNull
    private String propertyA;
    
    @Digits(when="groovy:_this.propertyA!=null")
    private String propertyB;
    

    此示例要求 Groovy 运行时位于类路径中。你也可以使用其他脚本语言,见http://oval.sourceforge.net/userguide.html#declaring-conditional-constraints

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-10-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多