下面列出了javax.validation.constraints.Size#min ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private String resolveSize(Field field) {
Size size = field.getAnnotation(Size.class);
if (size != null) {
if (size.min() == 0) {
return StrUtil.concat("长度不能大于", String.valueOf(size.max()));
} else {
return StrUtil.concat("长度不能小于", String.valueOf(size.min()), "且不能大于", String.valueOf(size.max()));
}
}
Length length = field.getAnnotation(Length.class);
if (length != null) {
if (length.min() == 0) {
return StrUtil.concat("长度不能大于", String.valueOf(length.max()));
} else {
return StrUtil.concat("长度不能小于", String.valueOf(length.min()), "且不能大于", String.valueOf(length.max()));
}
}
return null;
}
/**
* Determine a given array type's minimum number of items.
*
* @param member the field or method to check
* @return specified minimum number of array items (or null)
* @see Size
*/
protected Integer resolveArrayMinItems(MemberScope<?, ?> member) {
if (member.isContainerType()) {
Size sizeAnnotation = this.getAnnotationFromFieldOrGetter(member, Size.class, Size::groups);
if (sizeAnnotation != null && sizeAnnotation.min() > 0) {
// minimum length greater than the default 0 was specified
return sizeAnnotation.min();
}
if (this.getAnnotationFromFieldOrGetter(member, NotEmpty.class, NotEmpty::groups) != null) {
return 1;
}
}
return null;
}
/**
* Determine a given text type's minimum number of characters.
*
* @param member the field or method to check
* @return specified minimum number of characters (or null)
* @see Size
* @see NotEmpty
* @see NotBlank
*/
protected Integer resolveStringMinLength(MemberScope<?, ?> member) {
if (member.getType().isInstanceOf(CharSequence.class)) {
Size sizeAnnotation = this.getAnnotationFromFieldOrGetter(member, Size.class, Size::groups);
if (sizeAnnotation != null && sizeAnnotation.min() > 0) {
// minimum length greater than the default 0 was specified
return sizeAnnotation.min();
}
if (this.getAnnotationFromFieldOrGetter(member, NotEmpty.class, NotEmpty::groups) != null
|| this.getAnnotationFromFieldOrGetter(member, NotBlank.class, NotBlank::groups) != null) {
return 1;
}
}
return null;
}
public SizeConstraints(Size size) {
this(size.max(), size.min());
}
@Override
public void initialize(Size constraintAnnotation) {
this.minSizeValue = constraintAnnotation.min();
this.maxSizeValue = constraintAnnotation.max();
}