@Data
public class TestData {
private Integer x;
private Integer y;
@AssertTrue
public boolean isValid() {
String message;
if (x > y) {
message = "message1..."; // here
return false;
}
else if (x < y) {
message = "messsage2..." // and here
return false;
}
else {
return true;
}
}
}
I know it's possible to set the message in the @AssertTrue
annotation (@AssertTrue(message = "default messsage")
), but I wonder if there is a way to dynamically set the message at runtime.