當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。