public class VerifyList implements ConstraintValidator<NotNullListCus, List<String>> {
@Override
public boolean isValid(List<String> list, ConstraintValidatorContext context) {
boolean empty = false;
if (list != null){
for (String s : list) {
// 判断字符串是否为空
empty = StringUtil.isNotEmpty(s);
}
}
return empty;
}
}
@Target({ElementType.METHOD, ElementType.FIELD, ElementType.ANNOTATION_TYPE, ElementType.CONSTRUCTOR, ElementType.PARAMETER, ElementType.TYPE_USE})
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Constraint(
validatedBy = {VerifyList.class}
)
public @interface NotNullListCus {
boolean isRequired() default false;
String message() default "字符串不能为空";
Class<?>[] groups() default {};
Class<? extends Payload>[] payload() default {};
}
