mirror of
https://github.com/hs-web/hsweb-framework.git
synced 2026-06-20 09:52:14 +08:00
优化对常用接口的默认实例化
This commit is contained in:
@@ -35,10 +35,10 @@ import java.util.function.Supplier;
|
||||
* @since 3.0
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public class MapperEntityFactory implements EntityFactory ,BeanFactory {
|
||||
private Map<Class, Mapper> realTypeMapper = new HashMap<>();
|
||||
private Logger logger = LoggerFactory.getLogger(this.getClass());
|
||||
private Map<String, PropertyCopier> copierCache = new HashMap<>();
|
||||
public class MapperEntityFactory implements EntityFactory, BeanFactory {
|
||||
private Map<Class, Mapper> realTypeMapper = new HashMap<>();
|
||||
private Logger logger = LoggerFactory.getLogger(this.getClass());
|
||||
private Map<String, PropertyCopier> copierCache = new HashMap<>();
|
||||
|
||||
private static final DefaultMapperFactory DEFAULT_MAPPER_FACTORY = clazz -> {
|
||||
String simpleClassName = clazz.getPackage().getName().concat(".Simple").concat(clazz.getSimpleName());
|
||||
@@ -159,6 +159,15 @@ public class MapperEntityFactory implements EntityFactory ,BeanFactory {
|
||||
if (defaultClass != null) {
|
||||
return newInstance(defaultClass);
|
||||
}
|
||||
if (Map.class == beanClass) {
|
||||
return (T) new HashMap<>();
|
||||
}
|
||||
if (List.class == beanClass) {
|
||||
return (T) new ArrayList<>();
|
||||
}
|
||||
if (Set.class == beanClass) {
|
||||
return (T) new HashSet<>();
|
||||
}
|
||||
|
||||
throw new NotFoundException("can't create instance for " + beanClass);
|
||||
}
|
||||
@@ -190,7 +199,7 @@ public class MapperEntityFactory implements EntityFactory ,BeanFactory {
|
||||
}
|
||||
|
||||
public static class Mapper<T> {
|
||||
Class<T> target;
|
||||
Class<T> target;
|
||||
Supplier<T> instanceGetter;
|
||||
|
||||
public Mapper(Class<T> target, Supplier<T> instanceGetter) {
|
||||
|
||||
@@ -59,4 +59,4 @@ public class User {
|
||||
|
||||
注意: 1,2的功能由`hsweb-commons-dao`模块去实现,如果你不没有使用hsweb自带的dao实现,可能无法使用此功能.
|
||||
|
||||
所有的字典都会注册到:`DictDefineRepository`,可通过此类去获取字典,以提供给前端或者其他地方使用.
|
||||
所有的字典都会注册到:`DictDefineRepository`,可通过此类去获取字典,以提供给前端或者其他地方使用.
|
||||
|
||||
Reference in New Issue
Block a user