|
||||||||||
| 上一个类 下一个类 | 框架 无框架 | |||||||||
| 摘要: 嵌套 | 字段 | 构造方法 | 方法 | 详细信息: 字段 | 构造方法 | 方法 | |||||||||
java.lang.Objectcom.baidu.unbiz.fluentvalidator.FluentValidator
@NotThreadSafe @Stateful public class FluentValidator
链式调用验证器
按照Fluent Interface风格实现的验证工具,以一种近似于可以语义解释的方式做对象的验证。 典型的调用方式如下:
Result ret = FluentValidator.checkAll().failFast()
.on(car.getLicensePlate(), new CarLicensePlateValidator())
.on(car.getManufacturer(), new CarManufacturerValidator())
.on(car.getSeatCount(), new CarSeatCountValidator())
.doValidate().result(toSimple());
| 字段摘要 | |
|---|---|
protected ValidateCallback |
defaultCb
默认验证回调 |
| 构造方法摘要 | |
|---|---|
protected |
FluentValidator()
私有构造方法,只能通过 checkAll()去创建对象 |
| 方法摘要 | ||
|---|---|---|
static FluentValidator |
checkAll()
创建FluentValidator |
|
static FluentValidator |
checkAll(Class... groups)
创建FluentValidator |
|
FluentValidator |
configure(Registry registry)
如果启用通过 FluentValidate注解方式的验证,需要寻找验证器实例,这里配置注册中心的步骤 |
|
protected void |
doAdd(ListAble<ValidatorElement> listAble)
将验证对象及其验证器放入 validatorElementList中 |
|
protected
|
doOn(T t)
在某个对象上通过 FluentValidate注解方式的验证,
需要保证configure(Registry)已经先执行配置完毕Registry |
|
FluentValidator |
doValidate()
按照默认验证回调条件,开始使用验证 |
|
FluentValidator |
doValidate(ValidateCallback cb)
按照指定验证回调条件,开始使用验证 |
|
FluentValidator |
failFast()
出错即退出 |
|
FluentValidator |
failOver()
出错不退出而继续 |
|
|
on(T t)
在某个对象上通过 FluentValidate注解方式的验证,
需要保证configure(Registry)已经先执行配置完毕Registry |
|
|
on(T t,
Validator<T> v)
在待验证对象t上,使用v验证器进行验证 |
|
|
on(T t,
ValidatorChain chain)
在待验证对象t上,使用chain验证器链进行验证 |
|
|
onEach(Collection<T> t)
在某个集合对象上通过 FluentValidate注解方式的验证,
需要保证configure(Registry)已经先执行配置完毕Registry
注:当集合为空时,则会跳过 |
|
|
onEach(Collection<T> t,
Validator<T> v)
在待验证对象集合t上,使用v验证器进行验证 注:当集合为空时,则会跳过 |
|
|
onEach(T[] t)
在某个数组对象上通过 FluentValidate注解方式的验证,
需要保证configure(Registry)已经先执行配置完毕Registry
注:当数组为空时,则会跳过 |
|
|
onEach(T[] t,
Validator<T> v)
在待验证对象数组t上,使用v验证器进行验证 注:当数组为空时,则会跳过 |
|
FluentValidator |
putAttribute2Context(String key,
Object value)
将键值对放入上下文 |
|
FluentValidator |
putClosure2Context(String key,
Closure value)
将闭包注入上下文 |
|
|
result(ResultCollector<T> resultCollector)
转换为对外的验证结果,在 FluentValidator.on(..).on(..).doValidate()这一连串“惰性求值”计算后的“及时求值”收殓出口。 |
|
FluentValidator |
setExcludeGroups(Class<?>[] excludeGroups)
设置排除的分组 |
|
FluentValidator |
setGroups(Class<?>[] groups)
设置分组 |
|
FluentValidator |
setIsFailFast(boolean isFailFast)
设置是否快速失败 |
|
FluentValidator |
when(boolean expression)
当满足 expression条件时,才去使用前一个Validator或者ValidatorChain来验证 |
|
FluentValidator |
withContext(ValidatorContext context)
使用已经存在的一个验证上下文,共享context本身以及验证结果 |
|
| 从类 java.lang.Object 继承的方法 |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| 字段详细信息 |
|---|
protected ValidateCallback defaultCb
| 构造方法详细信息 |
|---|
protected FluentValidator()
checkAll()去创建对象
| 方法详细信息 |
|---|
public FluentValidator putAttribute2Context(String key,
Object value)
key - 键value - 值
public FluentValidator putClosure2Context(String key,
Closure value)
key - 键value - 闭包
public static FluentValidator checkAll()
public static FluentValidator checkAll(Class... groups)
groups - 分组
public FluentValidator withContext(ValidatorContext context)
context - 验证上下文
public FluentValidator failFast()
public FluentValidator failOver()
public FluentValidator configure(Registry registry)
FluentValidate注解方式的验证,需要寻找验证器实例,这里配置注册中心的步骤
registry - 验证器注册查找器
public <T> FluentValidator on(T t)
FluentValidate注解方式的验证,
需要保证configure(Registry)已经先执行配置完毕Registry
t - 待验证对象
public <T> FluentValidator onEach(T[] t)
FluentValidate注解方式的验证,
需要保证configure(Registry)已经先执行配置完毕Registry
注:当数组为空时,则会跳过
t - 待验证对象
public <T> FluentValidator onEach(Collection<T> t)
FluentValidate注解方式的验证,
需要保证configure(Registry)已经先执行配置完毕Registry
注:当集合为空时,则会跳过
t - 待验证对象
protected <T> MultiValidatorElement doOn(T t)
FluentValidate注解方式的验证,
需要保证configure(Registry)已经先执行配置完毕Registry
t - 待验证对象
public <T> FluentValidator on(T t,
Validator<T> v)
t - 待验证对象v - 验证器
public <T> FluentValidator on(T t,
ValidatorChain chain)
t - 待验证对象chain - 验证器链
public <T> FluentValidator onEach(T[] t,
Validator<T> v)
t - 待验证对象数组v - 验证器
public <T> FluentValidator onEach(Collection<T> t,
Validator<T> v)
t - 待验证对象集合v - 验证器
protected void doAdd(ListAble<ValidatorElement> listAble)
validatorElementList中
listAble - 验证对象及其验证器封装类public FluentValidator when(boolean expression)
expression条件时,才去使用前一个Validator或者ValidatorChain来验证
expression - 满足条件表达式
public FluentValidator doValidate()
public FluentValidator doValidate(ValidateCallback cb)
cb - 验证回调
ValidateCallbackpublic <T> T result(ResultCollector<T> resultCollector)
FluentValidator.on(..).on(..).doValidate()这一连串“惰性求值”计算后的“及时求值”收殓出口。
<T>是验证结果的泛型
resultCollector - 验证结果收集器
public FluentValidator setGroups(Class<?>[] groups)
groups - 分组
public FluentValidator setIsFailFast(boolean isFailFast)
isFailFast - 是否快速失败
public FluentValidator setExcludeGroups(Class<?>[] excludeGroups)
excludeGroups - 排除分组
|
||||||||||
| 上一个类 下一个类 | 框架 无框架 | |||||||||
| 摘要: 嵌套 | 字段 | 构造方法 | 方法 | 详细信息: 字段 | 构造方法 | 方法 | |||||||||