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


Java ConstraintViolation.getMessage方法代码示例

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


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

示例1: validate

import javax.validation.ConstraintViolation; //导入方法依赖的package包/类
@Override
public void validate(Object entity) throws HttpException {
    ValidatorFactory factory = Validation.buildDefaultValidatorFactory();
    Validator validator = factory.getValidator();

    Set<ConstraintViolation<Object>> violations = validator.validate(entity);
    if (!violations.isEmpty()) {
        List<ConstraintViolationDescription> errors = new ArrayList<>();

        ConstraintViolationResponseError error = new ConstraintViolationResponseError();
        error.setMessage(UNPROCESSABLE_ENTITY_MESSAGE);

        for (ConstraintViolation<Object> violation : violations) {
            String attribute = violation.getPropertyPath().toString();
            String message = violation.getMessage();
            errors.add(new ConstraintViolationDescription(message, attribute));
        }

        error.setErrors(errors);
        throw new UnprocessableEntityException(error);
    }
    
}
 
开发者ID:tdsis,项目名称:lambda-forest,代码行数:24,代码来源:DefaultRequestValidator.java

示例2: handleConstraintViolation

import javax.validation.ConstraintViolation; //导入方法依赖的package包/类
private void handleConstraintViolation(ConstraintViolationException violationException){

        Set<ConstraintViolation<?>> violationSet = violationException.getConstraintViolations();
        String[] messages = new String[violationSet.size()];

        int i = 0;
        for(ConstraintViolation violation: violationSet){
            messages[i] = violation.getMessage();
            i++;
        }

        Gson gson = appContext.getGsonBuilder().create();

        Map details = new HashMap<>();
        details.put("messages",messages);

        Map exception = new HashMap<>();
        exception.put("type",ConstraintViolationException.class.getSimpleName());
        exception.put("details",details);

        String resp = gson.toJson(exception);
        requestContext.getResponse().setStatus(500);
        requestContext.getResponse().setContentType("text/json;charset=UTF8");
        requestContext.echo(resp);

    }
 
开发者ID:Emerjoin,项目名称:Hi-Framework,代码行数:27,代码来源:FrontiersReqHandler.java

示例3: verifyMethod

import javax.validation.ConstraintViolation; //导入方法依赖的package包/类
/**
 * Validate the method parameters based on javax.validation: Hibernate Validator.
 *
 * @param proxy  The checked target object.
 * @param method The checked target method.
 * @param args   The checked target method's parameters.
 * @param <T>    The target object type: Generic types.
 */
public <T> void verifyMethod(
        final T proxy,
        final Method method,
        final Object[] args) {
    // 1. Get method validator
    final ExecutableValidator validatorParam
            = VALIDATOR.forExecutables();
    // 2. Create new params that wait for validation
    final Set<ConstraintViolation<T>> constraints
            = validatorParam.validateParameters(proxy, method, args);
    // 3. Throw out exception
    if (!constraints.isEmpty()) {
        final ConstraintViolation<T> item = constraints.iterator().next();
        if (null != item) {
            final WebException error
                    = new _400ValidationException(getClass(),
                    proxy.getClass(), method, item.getMessage());
            error.setReadible(item.getMessage());
            throw error;
        }
    }
}
 
开发者ID:silentbalanceyh,项目名称:vertx-zero,代码行数:31,代码来源:Validator.java

示例4: 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

示例5: 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

示例6: validateEntity

import javax.validation.ConstraintViolation; //导入方法依赖的package包/类
/**
 * 校验对象
 * @param object        待校验对象
 * @param groups        待校验的组
 * @throws RRException  校验不通过,则报RRException异常
 */
public static void validateEntity(Object object, Class<?>... groups)
        throws RRException {
    Set<ConstraintViolation<Object>> constraintViolations = validator.validate(object, groups);
    if (!constraintViolations.isEmpty()) {
    	ConstraintViolation<Object> constraint = (ConstraintViolation<Object>)constraintViolations.iterator().next();
        throw new RRException(constraint.getMessage());
    }
}
 
开发者ID:zhaoqicheng,项目名称:renren-fast,代码行数:15,代码来源:ValidatorUtils.java

示例7: 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();
}
 
开发者ID:syndesisio,项目名称:syndesis,代码行数:11,代码来源:Violation.java

示例8: check

import javax.validation.ConstraintViolation; //导入方法依赖的package包/类
/**
 * 检查参数是否符合注解(用户自行加的验证注解)
 *
 * @param params 参数
 * @throws ValidationException 当参数不符合规定时抛出该异常
 */
public void check(Object[] params) throws ValidationException {
    Set<ConstraintViolation<T>> methodValidators = executableValidator.validateParameters(instance,
            resourceMethod, params);
    for (ConstraintViolation<T> constraintViolation : methodValidators) {
        throw new ValidationException(constraintViolation.getMessage());
    }
}
 
开发者ID:935237604,项目名称:easysocket,代码行数:14,代码来源:Resource.java

示例9: handle

import javax.validation.ConstraintViolation; //导入方法依赖的package包/类
@ExceptionHandler
@ResponseBody
@ResponseStatus(HttpStatus.BAD_REQUEST)
public String handle(ConstraintViolationException exception) {
    List<ConstraintViolation<?>> constraintViolations =
            Lists.newArrayList(exception.getConstraintViolations());
    ConstraintViolation<?> constraintViolation = constraintViolations.get(0);

    return "bad request, " + constraintViolation.getMessage();
}
 
开发者ID:code4wt,项目名称:short-url,代码行数:11,代码来源:GlobalExceptionHandler.java

示例10: validMust

import javax.validation.ConstraintViolation; //导入方法依赖的package包/类
private void validMust(PayRequest request) throws Exception {
	Validator validator = Validation.buildDefaultValidatorFactory().getValidator();
	validator.validate(request.getMust());
	Set<ConstraintViolation<PayMustData>> validators = validator.validate(request.getMust());
	for (ConstraintViolation<PayMustData> constraintViolation : validators) {
		throw new Exception(constraintViolation.getMessage());
	}
}
 
开发者ID:yi-jun,项目名称:aaden-pay,代码行数:9,代码来源:PaymentValidate.java

示例11: validCash

import javax.validation.ConstraintViolation; //导入方法依赖的package包/类
private void validCash(PayRequest request) throws Exception {
	Validator validator = Validation.buildDefaultValidatorFactory().getValidator();
	validator.validate(request.getCash());
	Set<ConstraintViolation<PayCashData>> validators = validator.validate(request.getCash());
	for (ConstraintViolation<PayCashData> constraintViolation : validators) {
		throw new Exception(constraintViolation.getMessage());
	}
}
 
开发者ID:yi-jun,项目名称:aaden-pay,代码行数:9,代码来源:PaymentValidate.java

示例12: validRecharge

import javax.validation.ConstraintViolation; //导入方法依赖的package包/类
private void validRecharge(PayRequest request) throws Exception {
	if (request.getSys().getPayType() == PayType.GATEWAY)
		return;
	Validator validator = Validation.buildDefaultValidatorFactory().getValidator();
	validator.validate(request.getRecharge());
	Set<ConstraintViolation<PayRechargeData>> validators = validator.validate(request.getRecharge());
	for (ConstraintViolation<PayRechargeData> constraintViolation : validators) {
		throw new Exception(constraintViolation.getMessage());
	}
}
 
开发者ID:yi-jun,项目名称:aaden-pay,代码行数:11,代码来源:PaymentValidate.java

示例13: handleServiceException

import javax.validation.ConstraintViolation; //导入方法依赖的package包/类
/**
 * 400 - Bad Request
 */
@ResponseStatus(HttpStatus.BAD_REQUEST)
@ExceptionHandler(ConstraintViolationException.class)
public Response handleServiceException(ConstraintViolationException e) {
    log.error("参数验证失败: {}", e);
    Set<ConstraintViolation<?>> violations = e.getConstraintViolations();
    ConstraintViolation<?> violation = violations.iterator().next();
    String message = violation.getMessage();
    return new Response().failure("parameter:" + message);
}
 
开发者ID:finefuture,项目名称:data-migration,代码行数:13,代码来源:HttpExceptionAdvice.java

示例14: validateEntityFields

import javax.validation.ConstraintViolation; //导入方法依赖的package包/类
public static <T> void validateEntityFields(Validator validator, T entity) {
    Set<ConstraintViolation<T>> errors = validator.validate(entity);
    Iterator<ConstraintViolation<T>> itErrors = errors.iterator();
    if (itErrors.hasNext()) {
        ConstraintViolation<T> violation = itErrors.next();
        throw new FieldNotValidException(violation.getPropertyPath().toString(), violation.getMessage());
    }
}
 
开发者ID:CLARIN-PL,项目名称:WordnetLoom,代码行数:9,代码来源:ValidationUtils.java

示例15: validate

import javax.validation.ConstraintViolation; //导入方法依赖的package包/类
public void validate(Object target, Errors errors) {
    Set<ConstraintViolation<Object>> constraintViolations = beanValidator.validate(target);
    for (ConstraintViolation<Object> constraintViolation : constraintViolations) {
        String propertyPath = constraintViolation.getPropertyPath().toString();
        String message = constraintViolation.getMessage();
        errors.rejectValue(propertyPath, "", message);
    }
    for(Validator validator: springValidators) {
        validator.validate(target, errors);
    }
}
 
开发者ID:TomirKlos,项目名称:Webstore,代码行数:12,代码来源:ProductValidator.java


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