本文整理汇总了Java中com.baidu.unbiz.fluentvalidator.ValidationError类的典型用法代码示例。如果您正苦于以下问题:Java ValidationError类的具体用法?Java ValidationError怎么用?Java ValidationError使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ValidationError类属于com.baidu.unbiz.fluentvalidator包,在下文中一共展示了ValidationError类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: testOnFailException
import com.baidu.unbiz.fluentvalidator.ValidationError; //导入依赖的package包/类
@Test(expected = MyException.class)
public void testOnFailException() {
Company company = CompanyBuilder.buildSimple();
company.getDepartmentList().get(0).setId(null);
Result ret = FluentValidator.checkAll()
.on(company, new HibernateSupportedValidator<Company>().setHiberanteValidator(validator))
.doValidate(new DefaultValidateCallback() {
@Override
public void onFail(ValidatorElementList validatorElementList, List<ValidationError> errors) {
System.err.println(errors);
throw new MyException("ERROR HERE!");
}
}).result(toSimple());
System.out.println(ret);
}
开发者ID:neoremind,项目名称:fluent-validator,代码行数:17,代码来源:HiberateSupportedValidatorTest.java
示例2: validate
import com.baidu.unbiz.fluentvalidator.ValidationError; //导入依赖的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: addCars
import com.baidu.unbiz.fluentvalidator.ValidationError; //导入依赖的package包/类
@Override
public Result addCars(List<Car> cars) {
Preconditions.checkNotNull(cars, "car should not be null");
Result result = FluentValidator.checkAll()
.configure(springApplicationContextRegistry)
.onEach(cars)
.doValidate(new DefaultValidateCallback() {
@Override
public void onFail(ValidatorElementList validatorElementList, List<ValidationError> errors) {
throw new CarException(errors.get(0).getErrorMsg());
}
@Override
public void onUncaughtException(Validator validator, Exception e, Object target) throws Exception {
throw new CarException(e);
}
})
.result(toSimple());
return result;
}
开发者ID:neoremind,项目名称:fluent-validator,代码行数:21,代码来源:GarageServiceImpl.java
示例4: validate
import com.baidu.unbiz.fluentvalidator.ValidationError; //导入依赖的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
示例5: validate
import com.baidu.unbiz.fluentvalidator.ValidationError; //导入依赖的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
示例6: validate
import com.baidu.unbiz.fluentvalidator.ValidationError; //导入依赖的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
示例7: validate
import com.baidu.unbiz.fluentvalidator.ValidationError; //导入依赖的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
示例8: validate
import com.baidu.unbiz.fluentvalidator.ValidationError; //导入依赖的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.ValidationError; //导入依赖的package包/类
@Override
public boolean validate(ValidatorContext context, Garage t) {
if (!CollectionUtil.isEmpty(t.getCarList())) {
if (t.getCarList().size() > MAX_CAR_NUM) {
context.addError(
ValidationError.create(MessageSupport.getText(GarageError.CAR_NUM_EXCEED_LIMIT.msg(),
MAX_CAR_NUM))
.setErrorCode(GarageError.CAR_NUM_EXCEED_LIMIT.code())
.setField("garage.cars")
.setInvalidValue(t.getCarList().size()));
return false;
}
}
return true;
}
开发者ID:neoremind,项目名称:fluent-validator,代码行数:16,代码来源:GarageCarNotExceedLimitValidator.java
示例10: validate
import com.baidu.unbiz.fluentvalidator.ValidationError; //导入依赖的package包/类
@Override
public boolean validate(ValidatorContext context, List<Car> cars) {
ComplexResult result = FluentValidator.checkAll().configure(registry)
.onEach(cars)
.doValidate()
.result(toComplex());
if (!result.isSuccess()) {
ValidationError error = result.getErrors().get(0);
context.addError(error);
return false;
}
return true;
}
开发者ID:neoremind,项目名称:fluent-validator,代码行数:15,代码来源:CarValidator.java
示例11: validate
import com.baidu.unbiz.fluentvalidator.ValidationError; //导入依赖的package包/类
@Override
public boolean validate(ValidatorContext context, String t) {
if (t.startsWith("NYC") || t.startsWith("LA") || t.startsWith("BJ")) {
return true;
}
context.addError(ValidationError.create(String.format(CarError.LICENSEPLATE_ERROR.msg(), t))
.setErrorCode(CarError.LICENSEPLATE_ERROR.code())
.setField("licensePlate")
.setInvalidValue(t));
return false;
}
开发者ID:neoremind,项目名称:fluent-validator,代码行数:12,代码来源:CarLicensePlateValidator.java
示例12: validate
import com.baidu.unbiz.fluentvalidator.ValidationError; //导入依赖的package包/类
@Override
public boolean validate(ValidatorContext context, List<Car> cars) {
if (cars.size() > MAX_CAR_NUM) {
context.addError(
ValidationError.create(MessageSupport.getText(GarageError.CAR_NUM_EXCEED_LIMIT.msg(),
MAX_CAR_NUM))
.setErrorCode(GarageError.CAR_NUM_EXCEED_LIMIT.code())
.setField("garage.cars")
.setInvalidValue(cars.size()));
return false;
}
return true;
}
开发者ID:neoremind,项目名称:fluent-validator,代码行数:14,代码来源:CarNotExceedLimitValidator.java
示例13: toValidationError
import com.baidu.unbiz.fluentvalidator.ValidationError; //导入依赖的package包/类
@Override
public ValidationError toValidationError(ConstraintViolation constraintViolation) {
return ValidationError.create(constraintViolation.getMessage())
.setField(constraintViolation.getPropertyPath().toString())
.setInvalidValue(constraintViolation.getInvalidValue());
}
开发者ID:neoremind,项目名称:fluent-validator,代码行数:7,代码来源:DefaultConstraintViolationTransformer.java
示例14: onFail
import com.baidu.unbiz.fluentvalidator.ValidationError; //导入依赖的package包/类
@Override
public void onFail(ValidatorElementList validatorElementList, List<ValidationError> errors) {
throw new CarException(errors.get(0).getErrorMsg());
}
开发者ID:neoremind,项目名称:fluent-validator,代码行数:5,代码来源:ValidateCarCallback.java
示例15: toValidationError
import com.baidu.unbiz.fluentvalidator.ValidationError; //导入依赖的package包/类
/**
* {@link ConstraintViolation}到{@link ValidationError}的转换
*
* @param constraintViolation hibernate的错误
*
* @return fluent-validator框架的错误ValidationError
*/
ValidationError toValidationError(ConstraintViolation constraintViolation);
开发者ID:neoremind,项目名称:fluent-validator,代码行数:9,代码来源:ConstraintViolationTransformer.java
注:本文中的com.baidu.unbiz.fluentvalidator.ValidationError类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论