本文整理匯總了Java中javax.validation.ConstraintViolation.getConstraintDescriptor方法的典型用法代碼示例。如果您正苦於以下問題:Java ConstraintViolation.getConstraintDescriptor方法的具體用法?Java ConstraintViolation.getConstraintDescriptor怎麽用?Java ConstraintViolation.getConstraintDescriptor使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.validation.ConstraintViolation
的用法示例。
在下文中一共展示了ConstraintViolation.getConstraintDescriptor方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: toCode
import javax.validation.ConstraintViolation; //導入方法依賴的package包/類
private String toCode(ConstraintViolation<?> violation) {
if (violation.getConstraintDescriptor() != null) {
Annotation annotation = violation.getConstraintDescriptor().getAnnotation();
if (annotation != null) {
Class<?> clazz = annotation.getClass();
Class<?> superclass = annotation.getClass().getSuperclass();
Class<?>[] interfaces = annotation.getClass().getInterfaces();
if (superclass == Proxy.class && interfaces.length == 1) {
clazz = interfaces[0];
}
return clazz.getName();
}
}
if (violation.getMessageTemplate() != null) {
return violation.getMessageTemplate().replace("{", "").replaceAll("}", "");
}
return null;
}
示例2: fromConstraintViolation
import javax.validation.ConstraintViolation; //導入方法依賴的package包/類
public static Violation fromConstraintViolation(final ConstraintViolation<?> constraintViolation) {
final String property = constraintViolation.getPropertyPath().toString();
final ConstraintDescriptor<?> constraintDescriptor = constraintViolation.getConstraintDescriptor();
final Annotation annotation = constraintDescriptor.getAnnotation();
final Class<? extends Annotation> annotationType = annotation.annotationType();
final String error = annotationType.getSimpleName();
final String message = constraintViolation.getMessage();
return new Builder().property(property).error(error).message(message).build();
}