java类javax.validation.constraints.NotBlank的实例源码

MinijaxConstraintDescriptor.java 文件源码 项目:minijax 阅读 22 收藏 0 点赞 0 评论 0
private static MinijaxConstraintDescriptor<NotBlank> buildNotBlankValidator(final NotBlank notBlank, final Class<?> valueClass) {
    if (CharSequence.class.isAssignableFrom(valueClass)) {
        return new MinijaxConstraintDescriptor<>(notBlank, NotBlankValidator.INSTANCE);
    }

    throw new ValidationException("Unsupported type for @NotBlank annotation: " + valueClass);
}
CustomerController.java 文件源码 项目:POC 阅读 26 收藏 0 点赞 0 评论 0
/**
 * Get customer using id. Returns HTTP 404 if customer not found
 *
 * @param customerId a {@link java.lang.Long} object.
 * @return retrieved customer
 * @throws com.poc.restfulpoc.exception.EntityNotFoundException if any.
 */
@GetMapping(value = "/rest/customers/{customerId}", produces = {
        MediaType.APPLICATION_JSON_VALUE, MediaType.APPLICATION_XML_VALUE })
public ResponseEntity<Customer> getCustomer(
        @PathVariable("customerId") @NotBlank Long customerId)
        throws EntityNotFoundException {
    log.info("Fetching Customer with id {}", customerId);
    final Customer user = customerService.getCustomer(customerId);
    if (user == null) {
        log.error("Customer with id {} not found", customerId);
        return new ResponseEntity<>(HttpStatus.NOT_FOUND);
    }
    return new ResponseEntity<>(user, HttpStatus.OK);
}
MinijaxConstraintDescriptor.java 文件源码 项目:minijax 阅读 24 收藏 0 点赞 0 评论 0
@SuppressWarnings("unchecked")
public static <T extends Annotation> MinijaxConstraintDescriptor<T> build(final AnnotatedType annotatedType, final T annotation) {
    final Constraint constraint = annotation.annotationType().getAnnotation(Constraint.class);
    if (constraint == null) {
        return null;
    }

    final Class<?> valueClass = ReflectionUtils.getRawType(annotatedType);
    final Class<?> annotationClass = annotation.annotationType();

    if (constraint.validatedBy().length > 0) {
        return buildDeclaredValidator(annotation, constraint.validatedBy()[0]);

    } else if (annotationClass == AssertFalse.class) {
        return (MinijaxConstraintDescriptor<T>) buildAssertFalseValidator((AssertFalse) annotation, valueClass);

    } else if (annotationClass == AssertTrue.class) {
        return (MinijaxConstraintDescriptor<T>) buildAssertTrueValidator((AssertTrue) annotation, valueClass);

    } else if (annotationClass == Max.class) {
        return (MinijaxConstraintDescriptor<T>) buildMaxValidator((Max) annotation, valueClass);

    } else if (annotationClass == Min.class) {
        return (MinijaxConstraintDescriptor<T>) buildMinValidator((Min) annotation, valueClass);

    } else if (annotationClass == NotBlank.class) {
        return (MinijaxConstraintDescriptor<T>) buildNotBlankValidator((NotBlank) annotation, valueClass);

    } else if (annotationClass == NotEmpty.class) {
        return (MinijaxConstraintDescriptor<T>) buildNotEmptyValidator((NotEmpty) annotation, valueClass);

    } else if (annotationClass == NotNull.class) {
        return (MinijaxConstraintDescriptor<T>) buildNotNullValidator((NotNull) annotation);

    } else if (annotationClass == Pattern.class) {
        return (MinijaxConstraintDescriptor<T>) buildPatternValidator((Pattern) annotation, valueClass);

    } else if (annotationClass == Size.class) {
        return (MinijaxConstraintDescriptor<T>) buildSizeValidator((Size) annotation, valueClass);

    } else {
        throw new ValidationException("Unrecognized constraint annotation: " + annotation);
    }
}
ExecuteMethodValidatorChecker.java 文件源码 项目:lastaflute 阅读 25 收藏 0 点赞 0 评论 0
protected void doCheckMismatchedValidatorAnnotation(Field field, Map<String, Class<?>> genericMap) { // recursive point
    pathDeque.push(field.getName());
    checkedTypeSet.add(field.getDeclaringClass());
    final Class<?> fieldType = deriveFieldType(field, genericMap);
    // *depends on JSON rule so difficult, check only physical mismatch here
    //if (isFormPropertyCannotNotNullType(fieldType)) {
    //    final Class<NotNull> notNullType = NotNull.class;
    //    if (field.getAnnotation(notNullType) != null) {
    //        throwExecuteMethodFormPropertyValidationMismatchException(property, notNullType);
    //    }
    //}
    if (isCannotNotEmptyType(fieldType)) {
        final Class<NotEmpty> notEmptyType = NotEmpty.class;
        if (field.getAnnotation(notEmptyType) != null) {
            throwExecuteMethodNotEmptyValidationMismatchException(field, notEmptyType);
        }
    }
    if (isCannotNotBlankType(fieldType)) {
        final Class<NotBlank> notBlankType = NotBlank.class;
        if (field.getAnnotation(notBlankType) != null) {
            throwExecuteMethodNotEmptyValidationMismatchException(field, notBlankType);
        }
    }
    if (isFormPropertyCannotRequiredPrimitiveType(fieldType)) {
        final Class<Required> requiredType = Required.class;
        if (field.getAnnotation(requiredType) != null) {
            throwExecuteMethodPrimitiveValidationMismatchException(field, requiredType);
        }
        final Class<NotNull> notNullType = NotNull.class;
        if (field.getAnnotation(notNullType) != null) {
            throwExecuteMethodPrimitiveValidationMismatchException(field, notNullType);
        }
    }
    if (Collection.class.isAssignableFrom(fieldType)) { // only collection, except array and map, simply
        doCheckGenericBeanValidationMismatch(field);
    } else if (mayBeNestedBeanType(fieldType)) {
        doCheckNestedValidationMismatch(fieldType);
        doCheckGenericBeanValidationMismatch(field);
    }
    pathDeque.pop();
}
AutoTagRequest.java 文件源码 项目:molgenis 阅读 23 收藏 0 点赞 0 评论 0
@NotBlank
public abstract String getEntityTypeId();
GetOntologyTermRequest.java 文件源码 项目:molgenis 阅读 20 收藏 0 点赞 0 评论 0
@NotBlank
public abstract String getSearchTerm();
FeedbackController.java 文件源码 项目:molgenis 阅读 25 收藏 0 点赞 0 评论 0
@NotBlank
public String getFeedback()
{
    return feedback;
}


问题


面经


文章

微信
公众号

扫码关注公众号