feat:框架完善,增加完整的支持
This commit is contained in:
parent
1db0697340
commit
8f4544603c
@ -1,5 +1,6 @@
|
|||||||
package com.flyfish.framework.beans.enums;
|
package com.flyfish.framework.beans.enums;
|
||||||
|
|
||||||
|
import com.flyfish.framework.beans.meta.BeanPropertyType;
|
||||||
import com.flyfish.framework.beans.meta.BeanValidation;
|
import com.flyfish.framework.beans.meta.BeanValidation;
|
||||||
import com.flyfish.framework.validation.annotations.Phone;
|
import com.flyfish.framework.validation.annotations.Phone;
|
||||||
import com.flyfish.framework.validation.enums.PhoneType;
|
import com.flyfish.framework.validation.enums.PhoneType;
|
||||||
@ -85,12 +86,12 @@ public enum ValidationCandidate {
|
|||||||
* @param annotations 注解集合
|
* @param annotations 注解集合
|
||||||
* @return 结果
|
* @return 结果
|
||||||
*/
|
*/
|
||||||
public static List<BeanValidation> produce(MergedAnnotations annotations) {
|
public static List<BeanValidation> produce(MergedAnnotations annotations, BeanPropertyType type) {
|
||||||
return Arrays.stream(values())
|
return Arrays.stream(values())
|
||||||
.flatMap(candidate -> candidate.annotations.stream()
|
.flatMap(candidate -> candidate.annotations.stream()
|
||||||
.map(annotations::get)
|
.map(annotations::get)
|
||||||
.filter(MergedAnnotation::isPresent)
|
.filter(MergedAnnotation::isPresent)
|
||||||
.map(candidate::produce)
|
.map(annotation -> candidate.produce(annotation, type))
|
||||||
).collect(Collectors.toList());
|
).collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -99,8 +100,10 @@ public enum ValidationCandidate {
|
|||||||
*
|
*
|
||||||
* @return 结果
|
* @return 结果
|
||||||
*/
|
*/
|
||||||
public BeanValidation produce(MergedAnnotation<?> annotation) {
|
public BeanValidation produce(MergedAnnotation<?> annotation, BeanPropertyType type) {
|
||||||
BeanValidation validation = new BeanValidation().setMessage(annotation.getString("message"));
|
BeanValidation validation = new BeanValidation()
|
||||||
|
.setType(type.getValidType())
|
||||||
|
.setMessage(annotation.getString("message"));
|
||||||
mapper.accept(annotation, validation);
|
mapper.accept(annotation, validation);
|
||||||
return validation;
|
return validation;
|
||||||
}
|
}
|
||||||
|
@ -163,7 +163,7 @@ public class BeanProperty {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// 优雅的处理校验
|
// 优雅的处理校验
|
||||||
property.setValidation(ValidationCandidate.produce(annotations));
|
property.setValidation(ValidationCandidate.produce(annotations, property.getType()));
|
||||||
} else if (strict) {
|
} else if (strict) {
|
||||||
property.setReadonly(true);
|
property.setReadonly(true);
|
||||||
return property;
|
return property;
|
||||||
|
@ -14,31 +14,36 @@ import java.util.function.BiPredicate;
|
|||||||
* bean属性的类型
|
* bean属性的类型
|
||||||
* 包含java类型到js的映射
|
* 包含java类型到js的映射
|
||||||
* 我们通过类型自动解析bean的缺省控件,并自动映射
|
* 我们通过类型自动解析bean的缺省控件,并自动映射
|
||||||
|
*
|
||||||
* @author wangyu
|
* @author wangyu
|
||||||
*/
|
*/
|
||||||
@Getter
|
@Getter
|
||||||
public enum BeanPropertyType {
|
public enum BeanPropertyType {
|
||||||
|
|
||||||
STRING("String", CharSequence.class),
|
STRING("String", "string", CharSequence.class),
|
||||||
NUMBER("Number", Number.class),
|
NUMBER("Number", "string", Number.class),
|
||||||
BOOLEAN("Boolean", Boolean.class),
|
BOOLEAN("Boolean", "boolean", Boolean.class),
|
||||||
DATE("Date", Date.class),
|
DATE("Date", "date", Date.class),
|
||||||
ENUM("Enum", Enum.class),
|
ENUM("Enum", Enum.class),
|
||||||
LIST("Array", Collection.class),
|
LIST("Array", "array", Collection.class),
|
||||||
DB_REF("Ref", Po.class),
|
DB_REF("Ref", Po.class),
|
||||||
OBJECT("Object", Object.class);
|
OBJECT("Object", "object", Object.class);
|
||||||
|
|
||||||
private final BiPredicate<PropertyDescriptor, Class<?>> acceptor;
|
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.name = name;
|
||||||
|
this.validType = validType;
|
||||||
this.classes = Arrays.asList(classes);
|
this.classes = Arrays.asList(classes);
|
||||||
this.acceptor = null;
|
this.acceptor = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private final String name;
|
BeanPropertyType(String name, Class<?>... classes) {
|
||||||
|
this(name, null, classes);
|
||||||
private final List<Class<?>> classes;
|
}
|
||||||
|
|
||||||
BeanPropertyType(String name, BiPredicate<PropertyDescriptor, Class<?>> predicate) {
|
BeanPropertyType(String name, BiPredicate<PropertyDescriptor, Class<?>> predicate) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user