Commit 082b19e33adca05a46399c78d1a29a2b527f4837

Authored by RuoYi
1 parent b779cf05

mapperLocations配置支持分隔符

ruoyi-framework/src/main/java/com/ruoyi/framework/config/MyBatisConfig.java
... ... @@ -2,6 +2,7 @@ package com.ruoyi.framework.config;
2 2  
3 3 import java.io.IOException;
4 4 import java.util.ArrayList;
  5 +import java.util.Arrays;
5 6 import java.util.HashSet;
6 7 import java.util.List;
7 8 import javax.sql.DataSource;
... ... @@ -21,6 +22,7 @@ import org.springframework.core.type.classreading.CachingMetadataReaderFactory;
21 22 import org.springframework.core.type.classreading.MetadataReader;
22 23 import org.springframework.core.type.classreading.MetadataReaderFactory;
23 24 import org.springframework.util.ClassUtils;
  25 +import com.ruoyi.common.utils.StringUtils;
24 26  
25 27 /**
26 28 * Mybatis支持*匹配扫描包
... ... @@ -89,6 +91,28 @@ public class MyBatisConfig
89 91 return typeAliasesPackage;
90 92 }
91 93  
  94 + public Resource[] resolveMapperLocations(String[] mapperLocations)
  95 + {
  96 + ResourcePatternResolver resourceResolver = new PathMatchingResourcePatternResolver();
  97 + List<Resource> resources = new ArrayList<Resource>();
  98 + if (mapperLocations != null)
  99 + {
  100 + for (String mapperLocation : mapperLocations)
  101 + {
  102 + try
  103 + {
  104 + Resource[] mappers = resourceResolver.getResources(mapperLocation);
  105 + resources.addAll(Arrays.asList(mappers));
  106 + }
  107 + catch (IOException e)
  108 + {
  109 + // ignore
  110 + }
  111 + }
  112 + }
  113 + return resources.toArray(new Resource[resources.size()]);
  114 + }
  115 +
92 116 @Bean
93 117 public SqlSessionFactory sqlSessionFactory(DataSource dataSource) throws Exception
94 118 {
... ... @@ -101,7 +125,7 @@ public class MyBatisConfig
101 125 final SqlSessionFactoryBean sessionFactory = new SqlSessionFactoryBean();
102 126 sessionFactory.setDataSource(dataSource);
103 127 sessionFactory.setTypeAliasesPackage(typeAliasesPackage);
104   - sessionFactory.setMapperLocations(new PathMatchingResourcePatternResolver().getResources(mapperLocations));
  128 + sessionFactory.setMapperLocations(resolveMapperLocations(StringUtils.split(mapperLocations, ",")));
105 129 sessionFactory.setConfigLocation(new DefaultResourceLoader().getResource(configLocation));
106 130 return sessionFactory.getObject();
107 131 }
... ...