0

How can I Hibernate validate a property that may also be empty? And more important: only validate IF the property is not empty, otherwise SKIP the validation?

private int age;
@AssertTrue(condition = "age != null") //something like this
boolean isAgeValid() {
     return age >= 0;
}

Is there any possibility?

4

1 回答 1

0

嗯好的,因为在注释级别无法克服这个问题,我将其更改为以下内容:

@AssertTrue
private boolean isAgeValid() {
     return StringUtils.isBlank(age) || age >= 0;
}

可能是目前最好的选择。

于 2013-10-29T10:03:48.317 回答