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


Java ValidatorContext类代码示例

本文整理汇总了Java中com.baidu.unbiz.fluentvalidator.ValidatorContext的典型用法代码示例。如果您正苦于以下问题:Java ValidatorContext类的具体用法?Java ValidatorContext怎么用?Java ValidatorContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: validate

import com.baidu.unbiz.fluentvalidator.ValidatorContext; //导入依赖的package包/类
@Override
public boolean validate(ValidatorContext context, T t) {
    Class<?>[] groups = GroupingHolder.getGrouping();
    Set<ConstraintViolation<T>> constraintViolations;
    if (ArrayUtil.isEmpty(groups)) {
        constraintViolations = HIBERANTE_VALIDATOR.validate(t);
    } else {
        constraintViolations = HIBERANTE_VALIDATOR.validate(t, groups);
    }
    if (CollectionUtil.isEmpty(constraintViolations)) {
        return true;
    } else {
        for (ConstraintViolation<T> constraintViolation : constraintViolations) {
            context.addError(constraintViolationTransformer.toValidationError(constraintViolation)
                    .setErrorCode(hibernateDefaultErrorCode));
        }
        return false;
    }
}
 
开发者ID:neoremind,项目名称:fluent-validator,代码行数:20,代码来源:HibernateSupportedValidator.java

示例2: validate

import com.baidu.unbiz.fluentvalidator.ValidatorContext; //导入依赖的package包/类
@Override
public boolean validate(ValidatorContext context, String t) {
    Boolean ignoreManufacturer = context.getAttribute("ignoreManufacturer", Boolean.class);
    if (ignoreManufacturer != null && ignoreManufacturer) {
        return true;
    }

    if (!manufacturerService.getAllManufacturers().contains(t)) {
        context.addError(ValidationError.create(String.format(CarError.MANUFACTURER_ERROR.msg(), t))
                .setErrorCode(CarError.MANUFACTURER_ERROR.code())
                .setField("manufacturer")
                .setInvalidValue(t));
        return false;
    }
    return true;
}
 
开发者ID:neoremind,项目名称:fluent-validator,代码行数:17,代码来源:CarManufacturerValidator.java

示例3: validate

import com.baidu.unbiz.fluentvalidator.ValidatorContext; //导入依赖的package包/类
@Override
public boolean validate(ValidatorContext context, String s) {
    if (null == s || s.length() > max || s.length() < min) {
        context.addError(ValidationError.create(String.format("%s长度必须介于%s~%s之间!", fieldName, min, max))
                .setErrorCode(-1)
                .setField(fieldName)
                .setInvalidValue(s));
        return false;
    }
    return true;
}
 
开发者ID:youngMen1,项目名称:-Spring-SpringMVC-Mybatis-,代码行数:12,代码来源:LengthValidator.java

示例4: validate

import com.baidu.unbiz.fluentvalidator.ValidatorContext; //导入依赖的package包/类
@Override
public boolean validate(ValidatorContext context, Integer integer) {
    if (null == integer || integer.intValue() > max || integer.intValue() < min) {
        context.addError(ValidationError.create(String.format("%s必须大于%s,小于%s", fieldName, max, min))
                .setErrorCode(-1)
                .setField(fieldName)
                .setInvalidValue(integer));
        return false;
    }
    return true;
}
 
开发者ID:youngMen1,项目名称:-Spring-SpringMVC-Mybatis-,代码行数:12,代码来源:SizeValidator.java

示例5: validate

import com.baidu.unbiz.fluentvalidator.ValidatorContext; //导入依赖的package包/类
@Override
public boolean validate(ValidatorContext context, String s) {
    if (null == s) {
        context.addError(ValidationError.create(String.format("%s不能为空!", fieldName))
                .setErrorCode(-1)
                .setField(fieldName)
                .setInvalidValue(s));
        return false;
    }
    return true;
}
 
开发者ID:youngMen1,项目名称:-Spring-SpringMVC-Mybatis-,代码行数:12,代码来源:NotNullValidator.java

示例6: validate

import com.baidu.unbiz.fluentvalidator.ValidatorContext; //导入依赖的package包/类
@Override
public boolean validate(ValidatorContext context, String str) {
    if (str.startsWith("Mr")) {
        //context.addErrorMsg("用户名不能以Mr开头");
    	context.addError(ValidationError.create("用户名不能以Mr开头").setErrorCode(100));
        return false;
    }
    return true;
}
 
开发者ID:tank2140896,项目名称:JavaWeb,代码行数:10,代码来源:UserController.java

示例7: validate

import com.baidu.unbiz.fluentvalidator.ValidatorContext; //导入依赖的package包/类
@Override
public boolean validate(ValidatorContext context, Company company) {
    if (company.getId() <= 0) {
        context.addErrorMsg(String.format(ErrorMsg.COMPANY_ID_INVALID.msg(), company.getId()));
        return false;
    }
    Date date = company.getEstablishTime();

    // company established time must before 2010-1-1
    if (date.after(DateUtil.getDate(2010, 1, 1))) {
        context.addErrorMsg(String.format(ErrorMsg.COMPANY_DATE_INVALID.msg(), date));
        return false;
    }
    return true;
}
 
开发者ID:neoremind,项目名称:fluent-validator,代码行数:16,代码来源:CompanyCustomValidator.java

示例8: validate

import com.baidu.unbiz.fluentvalidator.ValidatorContext; //导入依赖的package包/类
@Override
public boolean validate(ValidatorContext context, String t) {
    String myname = context.getAttribute("myname", String.class);
    if (myname != null && myname.equals("pass")) {
        return true;
    }
    System.out.println("check " + t);
    if (!t.startsWith("abc")) {
        context.addError(ValidationError.create("string should be abc").setErrorCode(100).setField("str")
                .setInvalidValue(t));
        return false;
    }
    return true;
}
 
开发者ID:neoremind,项目名称:fluent-validator,代码行数:15,代码来源:StringValidator.java

示例9: validate

import com.baidu.unbiz.fluentvalidator.ValidatorContext; //导入依赖的package包/类
@Override
public boolean validate(ValidatorContext context, Integer t) {
    if (t != 2 && t != 5 && t != 7) {
        context.addErrorMsg(String.format(CarError.SEATCOUNT_ERROR.msg(), t));
        return false;
    }
    return true;
}
 
开发者ID:neoremind,项目名称:fluent-validator,代码行数:9,代码来源:CarSeatCountValidator.java

示例10: validate

import com.baidu.unbiz.fluentvalidator.ValidatorContext; //导入依赖的package包/类
@Override
public boolean validate(ValidatorContext context, Car car) {
    Closure<List<String>> closure = context.getClosure("manufacturerClosure");
    if (closure != null) {
        List<String> manufacturers = closure.executeAndGetResult();

        if (!manufacturers.contains(car.getManufacturer())) {
            context.addErrorMsg(String.format(CarError.MANUFACTURER_ERROR.msg(), car.getManufacturer()));
            return false;
        }
    }

    return true;
}
 
开发者ID:neoremind,项目名称:fluent-validator,代码行数:15,代码来源:CarValidator.java

示例11: validate

import com.baidu.unbiz.fluentvalidator.ValidatorContext; //导入依赖的package包/类
@Override
public boolean validate(ValidatorContext context, String t) {
    if (t.startsWith("NYC") || t.startsWith("LA") || t.startsWith("BEIJING")) {
        if (!normalMockRpcService.isValid(t)) {
            context.addErrorMsg(String.format(CarError.LICENSEPLATE_ERROR.msg(), t));
            return false;
        }
    } else {
        if (abNormalMockRpcService.isValid(t)) {
            context.addErrorMsg(String.format(CarError.LICENSEPLATE_ERROR.msg(), t));
            return false;
        }
    }
    return true;
}
 
开发者ID:neoremind,项目名称:fluent-validator,代码行数:16,代码来源:CarLicensePlateValidator.java

示例12: validate

import com.baidu.unbiz.fluentvalidator.ValidatorContext; //导入依赖的package包/类
@Override
public boolean validate(ValidatorContext context, Object t) {
    if (t == null) {
        context.addErrorMsg("Null is not expected!");
        return false;
    }
    return true;
}
 
开发者ID:neoremind,项目名称:fluent-validator,代码行数:9,代码来源:NotNullValidator.java

示例13: validate

import com.baidu.unbiz.fluentvalidator.ValidatorContext; //导入依赖的package包/类
@Override
public boolean validate(ValidatorContext context, Car car) {
    if (car.getSeatCount() != 2 && car.getSeatCount() != 5 && car.getSeatCount() != 7) {
        context.addErrorMsg(String.format(CarError.SEATCOUNT_ERROR.msg(), car.getSeatCount()));
        return false;
    }

    return true;
}
 
开发者ID:neoremind,项目名称:fluent-validator,代码行数:10,代码来源:CarValidator3.java

示例14: validate

import com.baidu.unbiz.fluentvalidator.ValidatorContext; //导入依赖的package包/类
@Override
public boolean validate(ValidatorContext context, String t) {
    Boolean ignoreManufacturer = context.getAttribute("ignoreManufacturer", Boolean.class);
    if (ignoreManufacturer != null && ignoreManufacturer) {
        return true;
    }
    if (!manufacturerService.getAllManufacturers().contains(t)) {
        context.addErrorMsg(String.format(CarError.MANUFACTURER_ERROR.msg(), t));
        return false;
    }
    return true;
}
 
开发者ID:neoremind,项目名称:fluent-validator,代码行数:13,代码来源:CarManufacturerValidator.java

示例15: validate

import com.baidu.unbiz.fluentvalidator.ValidatorContext; //导入依赖的package包/类
@Override
public boolean validate(ValidatorContext context, Car car) {
    if (!car.getLicensePlate().startsWith("NYC")
            && !car.getLicensePlate().startsWith("LA")
            && !car.getLicensePlate().startsWith("BEIJING")) {
        context.addErrorMsg(String.format(CarError.LICENSEPLATE_ERROR.msg(), car.getLicensePlate()));
        return false;
    }

    return true;
}
 
开发者ID:neoremind,项目名称:fluent-validator,代码行数:12,代码来源:CarValidator2.java


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