diff --git a/flyfish-web/src/main/java/com/flyfish/framework/beans/enums/ValidationCandidate.java b/flyfish-web/src/main/java/com/flyfish/framework/beans/enums/ValidationCandidate.java index c75452e..51ef576 100644 --- a/flyfish-web/src/main/java/com/flyfish/framework/beans/enums/ValidationCandidate.java +++ b/flyfish-web/src/main/java/com/flyfish/framework/beans/enums/ValidationCandidate.java @@ -1,5 +1,6 @@ package com.flyfish.framework.beans.enums; +import com.flyfish.framework.beans.meta.BeanPropertyType; import com.flyfish.framework.beans.meta.BeanValidation; import com.flyfish.framework.validation.annotations.Phone; import com.flyfish.framework.validation.enums.PhoneType; @@ -85,12 +86,12 @@ public enum ValidationCandidate { * @param annotations 注解集合 * @return 结果 */ - public static List produce(MergedAnnotations annotations) { + public static List produce(MergedAnnotations annotations, BeanPropertyType type) { return Arrays.stream(values()) .flatMap(candidate -> candidate.annotations.stream() .map(annotations::get) .filter(MergedAnnotation::isPresent) - .map(candidate::produce) + .map(annotation -> candidate.produce(annotation, type)) ).collect(Collectors.toList()); } @@ -99,8 +100,10 @@ public enum ValidationCandidate { * * @return 结果 */ - public BeanValidation produce(MergedAnnotation annotation) { - BeanValidation validation = new BeanValidation().setMessage(annotation.getString("message")); + public BeanValidation produce(MergedAnnotation annotation, BeanPropertyType type) { + BeanValidation validation = new BeanValidation() + .setType(type.getValidType()) + .setMessage(annotation.getString("message")); mapper.accept(annotation, validation); return validation; } diff --git a/flyfish-web/src/main/java/com/flyfish/framework/beans/meta/BeanProperty.java b/flyfish-web/src/main/java/com/flyfish/framework/beans/meta/BeanProperty.java index 6a3916c..c19544c 100644 --- a/flyfish-web/src/main/java/com/flyfish/framework/beans/meta/BeanProperty.java +++ b/flyfish-web/src/main/java/com/flyfish/framework/beans/meta/BeanProperty.java @@ -163,7 +163,7 @@ public class BeanProperty { } } // 优雅的处理校验 - property.setValidation(ValidationCandidate.produce(annotations)); + property.setValidation(ValidationCandidate.produce(annotations, property.getType())); } else if (strict) { property.setReadonly(true); return property; diff --git a/flyfish-web/src/main/java/com/flyfish/framework/beans/meta/BeanPropertyType.java b/flyfish-web/src/main/java/com/flyfish/framework/beans/meta/BeanPropertyType.java index fcc3444..f3ec65b 100644 --- a/flyfish-web/src/main/java/com/flyfish/framework/beans/meta/BeanPropertyType.java +++ b/flyfish-web/src/main/java/com/flyfish/framework/beans/meta/BeanPropertyType.java @@ -14,31 +14,36 @@ import java.util.function.BiPredicate; * bean属性的类型 * 包含java类型到js的映射 * 我们通过类型自动解析bean的缺省控件,并自动映射 + * * @author wangyu */ @Getter public enum BeanPropertyType { - STRING("String", CharSequence.class), - NUMBER("Number", Number.class), - BOOLEAN("Boolean", Boolean.class), - DATE("Date", Date.class), + STRING("String", "string", CharSequence.class), + NUMBER("Number", "string", Number.class), + BOOLEAN("Boolean", "boolean", Boolean.class), + DATE("Date", "date", Date.class), ENUM("Enum", Enum.class), - LIST("Array", Collection.class), + LIST("Array", "array", Collection.class), DB_REF("Ref", Po.class), - OBJECT("Object", Object.class); + OBJECT("Object", "object", Object.class); private final BiPredicate> acceptor; + private final String name; + private final List> classes; + private String validType; - BeanPropertyType(String name, Class... classes) { + BeanPropertyType(String name, String validType, Class... classes) { this.name = name; + this.validType = validType; this.classes = Arrays.asList(classes); this.acceptor = null; } - private final String name; - - private final List> classes; + BeanPropertyType(String name, Class... classes) { + this(name, null, classes); + } BeanPropertyType(String name, BiPredicate> predicate) { this.name = name;