Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
F
finance-manage
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
finance-oa
finance-manage
Commits
082b19e3
Commit
082b19e3
authored
Nov 02, 2020
by
RuoYi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
mapperLocations配置支持分隔符
parent
b779cf05
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
25 additions
and
1 deletion
+25
-1
ruoyi-framework/src/main/java/com/ruoyi/framework/config/MyBatisConfig.java
...c/main/java/com/ruoyi/framework/config/MyBatisConfig.java
+25
-1
No files found.
ruoyi-framework/src/main/java/com/ruoyi/framework/config/MyBatisConfig.java
View file @
082b19e3
...
...
@@ -2,6 +2,7 @@ package com.ruoyi.framework.config;
import
java.io.IOException
;
import
java.util.ArrayList
;
import
java.util.Arrays
;
import
java.util.HashSet
;
import
java.util.List
;
import
javax.sql.DataSource
;
...
...
@@ -21,6 +22,7 @@ import org.springframework.core.type.classreading.CachingMetadataReaderFactory;
import
org.springframework.core.type.classreading.MetadataReader
;
import
org.springframework.core.type.classreading.MetadataReaderFactory
;
import
org.springframework.util.ClassUtils
;
import
com.ruoyi.common.utils.StringUtils
;
/**
* Mybatis支持*匹配扫描包
...
...
@@ -89,6 +91,28 @@ public class MyBatisConfig
return
typeAliasesPackage
;
}
public
Resource
[]
resolveMapperLocations
(
String
[]
mapperLocations
)
{
ResourcePatternResolver
resourceResolver
=
new
PathMatchingResourcePatternResolver
();
List
<
Resource
>
resources
=
new
ArrayList
<
Resource
>();
if
(
mapperLocations
!=
null
)
{
for
(
String
mapperLocation
:
mapperLocations
)
{
try
{
Resource
[]
mappers
=
resourceResolver
.
getResources
(
mapperLocation
);
resources
.
addAll
(
Arrays
.
asList
(
mappers
));
}
catch
(
IOException
e
)
{
// ignore
}
}
}
return
resources
.
toArray
(
new
Resource
[
resources
.
size
()]);
}
@Bean
public
SqlSessionFactory
sqlSessionFactory
(
DataSource
dataSource
)
throws
Exception
{
...
...
@@ -101,7 +125,7 @@ public class MyBatisConfig
final
SqlSessionFactoryBean
sessionFactory
=
new
SqlSessionFactoryBean
();
sessionFactory
.
setDataSource
(
dataSource
);
sessionFactory
.
setTypeAliasesPackage
(
typeAliasesPackage
);
sessionFactory
.
setMapperLocations
(
new
PathMatchingResourcePatternResolver
().
getResources
(
mapperLocations
));
sessionFactory
.
setMapperLocations
(
resolveMapperLocations
(
StringUtils
.
split
(
mapperLocations
,
","
)
));
sessionFactory
.
setConfigLocation
(
new
DefaultResourceLoader
().
getResource
(
configLocation
));
return
sessionFactory
.
getObject
();
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment