Ver código fonte

优化字段拓展

zhouhao 7 anos atrás
pai
commit
a9ceb594b5

+ 8 - 31
hsweb-starter/hsweb-spring-boot-starter/src/main/java/org/hswebframework/web/starter/HswebAutoConfiguration.java

@@ -24,22 +24,18 @@ import com.alibaba.fastjson.parser.ParserConfig;
 import com.alibaba.fastjson.parser.deserializer.JavaBeanDeserializer;
 import com.alibaba.fastjson.parser.deserializer.ObjectDeserializer;
 import com.alibaba.fastjson.serializer.SerializerFeature;
-import org.hsweb.ezorm.rdb.executor.AbstractJdbcSqlExecutor;
-import org.hsweb.ezorm.rdb.executor.SqlExecutor;
 import org.hswebframework.web.ThreadLocalUtils;
 import org.hswebframework.web.commons.entity.Entity;
 import org.hswebframework.web.commons.entity.factory.EntityFactory;
 import org.hswebframework.web.commons.entity.factory.MapperEntityFactory;
-import org.hswebframework.web.commons.entity.factory.PropertyCopier;
 import org.hswebframework.web.commons.model.Model;
-import org.hswebframework.web.dao.datasource.DataSourceHolder;
-import org.hswebframework.web.dao.datasource.DatabaseType;
 import org.hswebframework.web.starter.convert.FastJsonHttpMessageConverter;
+import org.hswebframework.web.starter.entity.EntityFactoryInitConfiguration;
+import org.hswebframework.web.starter.entity.EntityProperties;
 import org.hswebframework.web.starter.resolver.AuthorizationArgumentResolver;
 import org.hswebframework.web.starter.resolver.JsonParamResolver;
-import org.springframework.beans.BeansException;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.beans.factory.config.BeanPostProcessor;
+import org.springframework.boot.autoconfigure.ImportAutoConfiguration;
 import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
 import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
 import org.springframework.boot.context.properties.ConfigurationProperties;
@@ -56,14 +52,11 @@ import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
 
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
-import javax.sql.DataSource;
 import javax.validation.Validation;
 import javax.validation.Validator;
 import javax.validation.ValidatorFactory;
 import java.lang.reflect.Modifier;
 import java.lang.reflect.Type;
-import java.sql.Connection;
-import java.sql.SQLException;
 import java.util.List;
 
 /**
@@ -74,6 +67,7 @@ import java.util.List;
 @Configuration
 @ComponentScan("org.hswebframework.web")
 @EnableConfigurationProperties(EntityProperties.class)
+@ImportAutoConfiguration(EntityFactoryInitConfiguration.class)
 public class HswebAutoConfiguration {
 
     @Autowired
@@ -158,30 +152,13 @@ public class HswebAutoConfiguration {
 
     @Bean(name = "entityFactory")
     @ConditionalOnMissingBean(EntityFactory.class)
-    public EntityFactory entityFactory() {
+    public MapperEntityFactory mapperEntityFactory() {
         return new MapperEntityFactory(entityProperties.createMappers());
     }
 
-
-    @Configuration
+    @Bean
     @ConditionalOnBean(MapperEntityFactory.class)
-    public class EntityFactoryInitConfiguration implements BeanPostProcessor {
-
-        @Autowired
-        private MapperEntityFactory mapperEntityFactory;
-
-
-        @Override
-        public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
-            return bean;
-        }
-
-        @Override
-        public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
-            if (bean instanceof PropertyCopier) {
-                mapperEntityFactory.addCopier(((PropertyCopier) bean));
-            }
-            return bean;
-        }
+    public EntityFactoryInitConfiguration entityFactoryInitConfiguration() {
+        return new EntityFactoryInitConfiguration();
     }
 }

+ 29 - 0
hsweb-starter/hsweb-spring-boot-starter/src/main/java/org/hswebframework/web/starter/entity/EntityFactoryInitConfiguration.java

@@ -0,0 +1,29 @@
+package org.hswebframework.web.starter.entity;
+
+import org.hswebframework.web.commons.entity.factory.MapperEntityFactory;
+import org.hswebframework.web.commons.entity.factory.PropertyCopier;
+import org.springframework.beans.BeansException;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.config.BeanPostProcessor;
+
+public class EntityFactoryInitConfiguration implements BeanPostProcessor {
+
+    @Autowired
+    private MapperEntityFactory mapperEntityFactory;
+
+    @Override
+    public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
+        return bean;
+    }
+
+    @Override
+    public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
+        if (bean instanceof PropertyCopier) {
+            mapperEntityFactory.addCopier(((PropertyCopier) bean));
+        }
+        if (bean instanceof EntityMappingCustomer) {
+            ((EntityMappingCustomer) bean).customize(mapperEntityFactory);
+        }
+        return bean;
+    }
+}

+ 12 - 0
hsweb-starter/hsweb-spring-boot-starter/src/main/java/org/hswebframework/web/starter/entity/EntityMappingCustomer.java

@@ -0,0 +1,12 @@
+package org.hswebframework.web.starter.entity;
+
+import org.hswebframework.web.commons.entity.factory.MapperEntityFactory;
+
+/**
+ * TODO 完成注释
+ *
+ * @author zhouhao
+ */
+public interface EntityMappingCustomer {
+    void customize(MapperEntityFactory entityFactory);
+}

+ 1 - 1
hsweb-starter/hsweb-spring-boot-starter/src/main/java/org/hswebframework/web/starter/EntityProperties.java

@@ -16,7 +16,7 @@
  *
  */
 
-package org.hswebframework.web.starter;
+package org.hswebframework.web.starter.entity;
 
 import org.hswebframework.web.commons.entity.Entity;
 import org.hswebframework.web.commons.entity.factory.MapperEntityFactory;