public class DateTimeValidator implements ConstraintValidator<DateTimeValidate, DateTime> {
private static final OffsetDateTime START_TIME = OffsetDateTime.parse("2015-10-20");
@Override
public boolean isValid(DateTime value, ConstraintValidatorContext context) {
if (value == null) {
return true;
}
if (value.getStartTime().isBefore(START_TIME)) {
String msg = "this is invalid";
setConstraintViolationMessage(START_DATE, msg, context);
return false;
}
}
@Override
public void initialize(DateTimeValidate constraintAnnotation) {
// TODO Auto-generated method stub
}
有没有办法让START_TIME动态化?在这个例子中,我已经在类本身中硬编码了这个值。我是否可以在属性文件中外化此属性,并且在编译验证器时,它会从属性文件中为START_TIME选取属性。