spring boot validation 两个值中必须有一个不为空()

@javax.validation.constraints.AssertTrue

public class MyModel {
    
    private String value1;
    private String value2;

    @AssertTrue(message = "Values are invalid")
    private boolean isValid() {
        return value1 != null || value2 != null;
    }
}

这样value1和value2不能都为空。

————————
@javax.validation.constraints.AssertTrue

public class MyModel {
    
    private String value1;
    private String value2;

    @AssertTrue(message = "Values are invalid")
    private boolean isValid() {
        return value1 != null || value2 != null;
    }
}

这样value1和value2不能都为空。