//不使用@valid进行校验
Set<ConstraintViolation<CommonValidator>> validates = validator.validateValue(CommonValidator.class, "name", null);
for (ConstraintViolation<CommonValidator> validate : validates) {
ConstraintViolationImpl validate2= (ConstraintViolationImpl)validate;
Annotation annotation = validate2.getConstraintDescriptor().getAnnotation();
Class<? extends Annotation> aClass = annotation.annotationType();
String messageTemplate = validate2.getConstraintDescriptor().getMessageTemplate();
System.out.println(validate.getMessage());
if (aClass.equals(NotEmpty.class)){
System.out.println("messageTemplate:"+messageTemplate);
throw new RuntimeException("not empty异常了");
}
}
System.out.println("成功");