正在显示
1 个修改的文件
包含
25 行增加
和
1 行删除
| @@ -2,6 +2,7 @@ package com.ruoyi.framework.config; | @@ -2,6 +2,7 @@ package com.ruoyi.framework.config; | ||
| 2 | 2 | ||
| 3 | import java.io.IOException; | 3 | import java.io.IOException; |
| 4 | import java.util.ArrayList; | 4 | import java.util.ArrayList; |
| 5 | +import java.util.Arrays; | ||
| 5 | import java.util.HashSet; | 6 | import java.util.HashSet; |
| 6 | import java.util.List; | 7 | import java.util.List; |
| 7 | import javax.sql.DataSource; | 8 | import javax.sql.DataSource; |
| @@ -21,6 +22,7 @@ import org.springframework.core.type.classreading.CachingMetadataReaderFactory; | @@ -21,6 +22,7 @@ import org.springframework.core.type.classreading.CachingMetadataReaderFactory; | ||
| 21 | import org.springframework.core.type.classreading.MetadataReader; | 22 | import org.springframework.core.type.classreading.MetadataReader; |
| 22 | import org.springframework.core.type.classreading.MetadataReaderFactory; | 23 | import org.springframework.core.type.classreading.MetadataReaderFactory; |
| 23 | import org.springframework.util.ClassUtils; | 24 | import org.springframework.util.ClassUtils; |
| 25 | +import com.ruoyi.common.utils.StringUtils; | ||
| 24 | 26 | ||
| 25 | /** | 27 | /** |
| 26 | * Mybatis支持*匹配扫描包 | 28 | * Mybatis支持*匹配扫描包 |
| @@ -89,6 +91,28 @@ public class MyBatisConfig | @@ -89,6 +91,28 @@ public class MyBatisConfig | ||
| 89 | return typeAliasesPackage; | 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 | @Bean | 116 | @Bean |
| 93 | public SqlSessionFactory sqlSessionFactory(DataSource dataSource) throws Exception | 117 | public SqlSessionFactory sqlSessionFactory(DataSource dataSource) throws Exception |
| 94 | { | 118 | { |
| @@ -101,7 +125,7 @@ public class MyBatisConfig | @@ -101,7 +125,7 @@ public class MyBatisConfig | ||
| 101 | final SqlSessionFactoryBean sessionFactory = new SqlSessionFactoryBean(); | 125 | final SqlSessionFactoryBean sessionFactory = new SqlSessionFactoryBean(); |
| 102 | sessionFactory.setDataSource(dataSource); | 126 | sessionFactory.setDataSource(dataSource); |
| 103 | sessionFactory.setTypeAliasesPackage(typeAliasesPackage); | 127 | sessionFactory.setTypeAliasesPackage(typeAliasesPackage); |
| 104 | - sessionFactory.setMapperLocations(new PathMatchingResourcePatternResolver().getResources(mapperLocations)); | 128 | + sessionFactory.setMapperLocations(resolveMapperLocations(StringUtils.split(mapperLocations, ","))); |
| 105 | sessionFactory.setConfigLocation(new DefaultResourceLoader().getResource(configLocation)); | 129 | sessionFactory.setConfigLocation(new DefaultResourceLoader().getResource(configLocation)); |
| 106 | return sessionFactory.getObject(); | 130 | return sessionFactory.getObject(); |
| 107 | } | 131 | } |
-
请 注册 或 登录 后发表评论