All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.github.opensabre.common.web.validator.EnumString Maven / Gradle / Ivy

The newest version!
package io.github.opensabre.common.web.validator;

import jakarta.validation.Constraint;
import jakarta.validation.Payload;

import java.lang.annotation.Documented;
import java.lang.annotation.Repeatable;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;

import static java.lang.annotation.ElementType.*;
import static java.lang.annotation.RetentionPolicy.RUNTIME;

/**
 * 枚举字符串校验器
 * 字段值只能为 value数组中的值
 */
@Target({METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER, TYPE_USE})
@Retention(RUNTIME)
@Repeatable(EnumString.List.class)
@Documented
@Constraint(validatedBy = EnumStringValidator.class)//标明由哪个类执行校验逻辑
public @interface EnumString {
    /**
     * 校验失败默认的提示信息
     *
     * @return 提示词
     */
    String message() default "类型只能为 value 列表内的值";

    Class[] groups() default {};

    Class[] payload() default {};

    /**
     * @return data must in this value array
     */
    String[] value();

    /**
     * Defines several {@link EnumString} annotations on the same element.
     *
     * @see EnumString
     */
    @Target({METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER, TYPE_USE})
    @Retention(RUNTIME)
    @Documented
    @interface List {
        EnumString[] value();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy