当前位置: 首页>>代码示例>>Java>>正文


Java ConstraintViolation.getPropertyPath方法代码示例

本文整理汇总了Java中javax.validation.ConstraintViolation.getPropertyPath方法的典型用法代码示例。如果您正苦于以下问题:Java ConstraintViolation.getPropertyPath方法的具体用法?Java ConstraintViolation.getPropertyPath怎么用?Java ConstraintViolation.getPropertyPath使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.validation.ConstraintViolation的用法示例。


在下文中一共展示了ConstraintViolation.getPropertyPath方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: prepareMessage

import javax.validation.ConstraintViolation; //导入方法依赖的package包/类
private static String prepareMessage(ConstraintViolation property) {
    if (!StringUtils.isEmpty(property.getPropertyPath().toString())) {
        return property.getPropertyPath() + " : " + property.getMessage();
    }

    return property.getMessage();
}
 
开发者ID:hmcts,项目名称:cmc-claim-store,代码行数:8,代码来源:BeanValidator.java

示例2: JSR303Validator

import javax.validation.ConstraintViolation; //导入方法依赖的package包/类
/**
 * 使用hibernate-validator实现的JSR303验证model
 */
public <T> void JSR303Validator(T model) {
  Set<ConstraintViolation<T>> constraintViolations = validator.validate(model);
  if(constraintViolations.size() == 0) return;
   for(ConstraintViolation<T> c : constraintViolations) {
     throw new AssertException("Oop~ " + c.getPropertyPath() + " " + c.getMessage());
   }
}
 
开发者ID:slashchenxiaojun,项目名称:wall.e,代码行数:11,代码来源:BaseController.java

示例3: getConstraintViolationField

import javax.validation.ConstraintViolation; //导入方法依赖的package包/类
/**
 * 通过根类和hibernate validator错误信息获取当前验证失败的field对象
 *
 * @param rootClass pojo根类, 如:User.class类包含属性info:Info.class,User即rootClass
 * @param cv        hibernate validator验证结果对象{@link ConstraintViolation}
 * @return 当前失败的field对象
 */
static Field getConstraintViolationField(Class<?> rootClass, ConstraintViolation<Object> cv) {

    try {
        Field field = null;
        for (Path.Node node : cv.getPropertyPath()) {
            String fieldName = node.getName();
            field = rootClass.getDeclaredField(fieldName);
            rootClass = field.getType();
        }
        return field;
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
 
开发者ID:Strangeen,项目名称:excel-util4j,代码行数:22,代码来源:ValidateKit.java

示例4: toResponse

import javax.validation.ConstraintViolation; //导入方法依赖的package包/类
@Override
public Response toResponse(ConstraintViolationException exception) {
    logger.info(String.format("%s. Returning %s response.", exception, Response.Status.BAD_REQUEST));

    if (logger.isDebugEnabled()) {
        logger.debug(StringUtils.EMPTY, exception);
    }

    // start with the overall message which will be something like "Cannot create xyz"
    final StringBuilder errorMessage = new StringBuilder(exception.getMessage()).append(" - ");

    boolean first = true;
    for (final ConstraintViolation violation : exception.getConstraintViolations()) {
        if (!first) {
            errorMessage.append(", ");
        }
        first = false;

        // lastNode should end up as the field that failed validation
        Path.Node lastNode = null;
        for (final Path.Node node : violation.getPropertyPath()) {
            lastNode = node;
        }

        // append something like "xyz must not be..."
        errorMessage.append(lastNode.getName()).append(" ").append(violation.getMessage());
    }

    return Response.status(Response.Status.BAD_REQUEST).entity(errorMessage.toString()).type("text/plain").build();
}
 
开发者ID:apache,项目名称:nifi-registry,代码行数:31,代码来源:ConstraintViolationExceptionMapper.java

示例5: contOnValidationError

import javax.validation.ConstraintViolation; //导入方法依赖的package包/类
/**
 * Accepts the result from one of the many validation methods available and
 * returns a List of ValidationErrors. If the size of the List is 0, no errors
 * were encounter during validation.
 *
 * Usage:
 * <pre>
 *     Validator validator = getValidator();
 *     List&lt;ValidationError&gt; errors = contOnValidationError(
 *         validator.validateProperty(myObject, "uuid"),
 *         validator.validateProperty(myObject, "name")
 *      );
 *      // If validation fails, this line will be reached.
 * </pre>
 *
 * @param violationsArray a Set of one or more ConstraintViolations
 * @return a List of zero or more ValidationErrors
 * @since 1.0.0
 */
@SafeVarargs
protected final List<ValidationError> contOnValidationError(final Set<ConstraintViolation<Object>>... violationsArray) {
    final List<ValidationError> errors = new ArrayList<>();
    for (Set<ConstraintViolation<Object>> violations : violationsArray) {
        for (ConstraintViolation violation : violations) {
            if (violation.getPropertyPath().iterator().next().getName() != null) {
                final String path = violation.getPropertyPath() != null ? violation.getPropertyPath().toString() : null;
                final String message = violation.getMessage() != null ? StringUtils.removeStart(violation.getMessage(), path + ".") : null;
                final String messageTemplate = violation.getMessageTemplate();
                final String invalidValue = violation.getInvalidValue() != null ? violation.getInvalidValue().toString() : null;
                final ValidationError error = new ValidationError(message, messageTemplate, path, invalidValue);
                errors.add(error);
            }
        }
    }
    return errors;
}
 
开发者ID:stevespringett,项目名称:Alpine,代码行数:37,代码来源:AlpineResource.java


注:本文中的javax.validation.ConstraintViolation.getPropertyPath方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。