feat:新增值联动和扩展覆盖属性
This commit is contained in:
parent
1b8d5e165c
commit
5e713b7fc2
@ -0,0 +1,38 @@
|
||||
package com.flyfish.framework.validation.annotations;
|
||||
|
||||
import com.flyfish.framework.validation.annotations.Money.List;
|
||||
import com.flyfish.framework.validation.validators.MoneyValidator;
|
||||
|
||||
import javax.validation.Constraint;
|
||||
import javax.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;
|
||||
|
||||
@Target({METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER})
|
||||
@Retention(RUNTIME)
|
||||
@Documented
|
||||
@Constraint(validatedBy = {MoneyValidator.class})
|
||||
@Repeatable(List.class)
|
||||
public @interface Money {
|
||||
|
||||
String message() default "不是合法的金额!";
|
||||
|
||||
//分组
|
||||
Class<?>[] groups() default {};
|
||||
|
||||
//负载
|
||||
Class<? extends Payload>[] payload() default {};
|
||||
|
||||
//指定多个时使用
|
||||
@Target({FIELD, METHOD, PARAMETER, ANNOTATION_TYPE})
|
||||
@Retention(RUNTIME)
|
||||
@Documented
|
||||
@interface List {
|
||||
Money[] value();
|
||||
}
|
||||
}
|
@ -0,0 +1,29 @@
|
||||
package com.flyfish.framework.validation.validators;
|
||||
|
||||
import com.flyfish.framework.validation.annotations.Money;
|
||||
|
||||
import javax.validation.ConstraintValidator;
|
||||
import javax.validation.ConstraintValidatorContext;
|
||||
|
||||
/**
|
||||
* 金额验证器
|
||||
* @author wangyu
|
||||
*/
|
||||
public class MoneyValidator implements ConstraintValidator<Money, Long> {
|
||||
|
||||
/**
|
||||
* Implements the validation logic.
|
||||
* The state of {@code value} must not be altered.
|
||||
* <p>
|
||||
* This method can be accessed concurrently, thread-safety must be ensured
|
||||
* by the implementation.
|
||||
*
|
||||
* @param value object to validate
|
||||
* @param context context in which the constraint is evaluated
|
||||
* @return {@code false} if {@code value} does not pass the constraint
|
||||
*/
|
||||
@Override
|
||||
public boolean isValid(Long value, ConstraintValidatorContext context) {
|
||||
return value >= 9;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user