001package cn.sticki.validator.spel.constrain; 002 003import cn.sticki.validator.spel.SpelConstraint; 004import cn.sticki.validator.spel.SpelValid; 005import cn.sticki.validator.spel.constraintvalidator.SpelNotNullValidator; 006import org.intellij.lang.annotations.Language; 007 008import java.lang.annotation.Documented; 009import java.lang.annotation.Repeatable; 010import java.lang.annotation.Retention; 011import java.lang.annotation.Target; 012 013import static java.lang.annotation.ElementType.FIELD; 014import static java.lang.annotation.RetentionPolicy.RUNTIME; 015 016/** 017 * 基于SpEL非空校验注解,用于标记被注解的元素不能为null。 018 * 019 * @author 阿杆 020 * @version 1.0 021 * @since 2024/5/1 022 */ 023@Documented 024@Retention(RUNTIME) 025@Target(FIELD) 026@Repeatable(SpelNotNull.List.class) 027@SpelConstraint(validatedBy = SpelNotNullValidator.class) 028public @interface SpelNotNull { 029 030 /** 031 * 校验失败时的错误消息 032 */ 033 String message() default "不能为null"; 034 035 /** 036 * 约束开启条件,必须为合法的SpEL表达式,计算结果必须为boolean类型。 037 * <p> 038 * 当 表达式为空 或 计算结果为true 时,会对带注解的元素进行校验。 039 * <p> 040 * 默认情况下,开启校验。 041 */ 042 @Language("SpEL") 043 String condition() default ""; 044 045 /** 046 * 分组条件,必须为合法的SpEL表达式。 047 * <p> 048 * 当分组信息不为空时,只有当 {@link SpelValid#spelGroups()} 中的分组信息与此处的分组信息有交集时,才会对带注解的元素进行校验。 049 * <p> 050 * 其计算结果可以是任何类型,但只有两个计算结果完全相等时,才被认为是相等的。 051 */ 052 @Language("SpEL") 053 String[] group() default {}; 054 055 /** 056 * 在同一元素上定义多个注解。 057 * 058 * @see SpelNotNull 059 */ 060 @Target(FIELD) 061 @Retention(RUNTIME) 062 @Documented 063 @interface List { 064 065 SpelNotNull[] value(); 066 067 } 068 069}