本文整理汇总了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();
}