Browse Source

fix mapper refresh bug

Caratacus 8 years ago
parent
commit
46538f0e66

+ 1 - 1
src/main/java/com/baomidou/mybatisplus/mapper/AutoSqlInjector.java

@@ -200,7 +200,7 @@ public class AutoSqlInjector implements ISqlInjector {
      */
     protected void injectInsertOneSql(boolean selective, Class<?> mapperClass, Class<?> modelClass, TableInfo table) {
         /*
-		 * INSERT INTO table <trim prefix="(" suffix=")" suffixOverrides=",">
+         * INSERT INTO table <trim prefix="(" suffix=")" suffixOverrides=",">
 		 * <if test="xx != null">xx,</if> </trim> <trim prefix="values ("
 		 * suffix=")" suffixOverrides=","> <if test="xx != null">#{xx},</if>
 		 * </trim>

+ 17 - 16
src/main/java/com/baomidou/mybatisplus/spring/MybatisMapperRefresh.java

@@ -94,7 +94,6 @@ public class MybatisMapperRefresh implements Runnable {
      * @param sleepSeconds
      * @param enabled
      */
-    @Deprecated
     public MybatisMapperRefresh(Resource[] mapperLocations, SqlSessionFactory sqlSessionFactory, int delaySeconds,
                                 int sleepSeconds, boolean enabled) {
         this.mapperLocations = mapperLocations.clone();
@@ -151,24 +150,26 @@ public class MybatisMapperRefresh implements Runnable {
                 public void run() {
                     if (fileSet == null) {
                         fileSet = new HashSet<>();
-                        for (Resource mapperLocation : mapperLocations) {
-                            try {
-                                if (ResourceUtils.isJarURL(mapperLocation.getURL())) {
-                                    String key = new UrlResource(ResourceUtils.extractJarFileURL(mapperLocation.getURL()))
-                                            .getFile().getPath();
-                                    fileSet.add(key);
-                                    if (jarMapper.get(key) != null) {
-                                        jarMapper.get(key).add(mapperLocation);
+                        if (mapperLocations != null) {
+                            for (Resource mapperLocation : mapperLocations) {
+                                try {
+                                    if (ResourceUtils.isJarURL(mapperLocation.getURL())) {
+                                        String key = new UrlResource(ResourceUtils.extractJarFileURL(mapperLocation.getURL()))
+                                                .getFile().getPath();
+                                        fileSet.add(key);
+                                        if (jarMapper.get(key) != null) {
+                                            jarMapper.get(key).add(mapperLocation);
+                                        } else {
+                                            List<Resource> resourcesList = new ArrayList<>();
+                                            resourcesList.add(mapperLocation);
+                                            jarMapper.put(key, resourcesList);
+                                        }
                                     } else {
-                                        List<Resource> resourcesList = new ArrayList<>();
-                                        resourcesList.add(mapperLocation);
-                                        jarMapper.put(key, resourcesList);
+                                        fileSet.add(mapperLocation.getFile().getPath());
                                     }
-                                } else {
-                                    fileSet.add(mapperLocation.getFile().getPath());
+                                } catch (IOException ioException) {
+                                    ioException.printStackTrace();
                                 }
-                            } catch (IOException ioException) {
-                                ioException.printStackTrace();
                             }
                         }
                     }

+ 1 - 1
src/main/java/com/baomidou/mybatisplus/spring/MybatisSqlSessionFactoryBean.java

@@ -525,7 +525,7 @@ public class MybatisSqlSessionFactoryBean implements FactoryBean<SqlSessionFacto
         if (!isEmpty(this.mapperLocations)) {
             if (globalConfig.isRefresh()) {
                 //TODO 设置自动刷新配置 减少配置
-                new MybatisMapperRefresh(sqlSessionFactory, 2,
+                new MybatisMapperRefresh(this.mapperLocations, sqlSessionFactory, 2,
                         2, true);
             }
             for (Resource mapperLocation : this.mapperLocations) {

+ 1 - 1
src/test/java/com/baomidou/mybatisplus/test/EntityWrapperTest.java

@@ -88,7 +88,7 @@ public class EntityWrapperTest {
     @Test
     public void test13() {
         /*
-		 * 实体排序
+         * 实体排序
 		 */
         ew.setEntity(new User(1));
         ew.orderBy("id", false);

+ 1 - 1
src/test/java/com/baomidou/mybatisplus/test/mysql/UserMapperTest.java

@@ -281,7 +281,7 @@ public class UserMapperTest {
         EntityWrapper<User> ew = new EntityWrapper<>(new User(1));
 
 		/*
-		 * 查询字段
+         * 查询字段
 		 */
         ew.setSqlSelect("age,name");