600字范文,内容丰富有趣,生活中的好帮手!
600字范文 > java oval 入门_java开源验证框架OVAL-Go语言中文社区

java oval 入门_java开源验证框架OVAL-Go语言中文社区

时间:2018-12-05 04:05:28

相关推荐

java oval 入门_java开源验证框架OVAL-Go语言中文社区

@Length,@MaxLength,@MinLength

maxLength,minLength只有value属性,表示和value进行比较

min和max是Length的属性

汉字算一个长度

@NotBlank、@NotNull、@NotEmpty

NotBlank:Check if the string representation is not empty and does not only contain white spaces.

NotNull:Check if not null.

NotEmpty:Check if the string representation is not empty ("").

@CheckWith

Check the value by a method of the sameclass that takes the value as argument and returns true if valid and false ifinvalid.

使用net.sf.oval.constraint.CheckWithCheck.SimpleCheck实现该接口的类中isSatisfied方法来判断,返回true有效,false无效;如果实现类是内部的,必须为静态类。

示例:验证User类中的age字段

@CheckWith(value=CheckAge.class,message="agemust in (18~65)")

private int age;

验证类如下:

publicclass CheckAge implements CheckWithCheck.SimpleCheck {

private static final long serialVersionUID =1L;

@Override

public boolean isSatisfied(Object validatedObject, Object value) {

if (!validatedObject instanceof User) {

return false;

}

User user = (User)validatedObject;

int age = user.getAge();

if(age <18 || age > 65)

return false;

else

return true;

}

}

完全验证

选择性验证(多个验证选择性验证)

List message = validator.validate(entity, profiles);

根据profiles进行选择性验证entity对象,可以指定多个profiles

验证对象的某个字段

public List validateFieldValue(final Object validatedObject, final Field validatedField,final Object fieldValueToValidate)

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。