feat:框架完善,增加完整的支持

This commit is contained in:
wangyu 2021-09-28 22:42:15 +08:00
parent 1db0697340
commit 8f4544603c
3 changed files with 23 additions and 15 deletions

View File

@ -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<BeanValidation> produce(MergedAnnotations annotations) {
public static List<BeanValidation> 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;
}

View File

@ -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;

View File

@ -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<PropertyDescriptor, Class<?>> acceptor;
private final String name;
private final List<Class<?>> 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<Class<?>> classes;
BeanPropertyType(String name, Class<?>... classes) {
this(name, null, classes);
}
BeanPropertyType(String name, BiPredicate<PropertyDescriptor, Class<?>> predicate) {
this.name = name;