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
41799c10
Commit
41799c10
authored
May 19, 2020
by
RuoYi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修改数据源类型优先级,先根据方法,再根据类
parent
25b114aa
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
9 additions
and
11 deletions
+9
-11
ruoyi/src/main/java/com/ruoyi/framework/aspectj/DataSourceAspect.java
...in/java/com/ruoyi/framework/aspectj/DataSourceAspect.java
+6
-10
ruoyi/src/main/java/com/ruoyi/framework/aspectj/lang/annotation/DataSource.java
...m/ruoyi/framework/aspectj/lang/annotation/DataSource.java
+3
-1
No files found.
ruoyi/src/main/java/com/ruoyi/framework/aspectj/DataSourceAspect.java
View file @
41799c10
package
com.ruoyi.framework.aspectj
;
package
com.ruoyi.framework.aspectj
;
import
java.
lang.reflect.Method
;
import
java.
util.Objects
;
import
org.aspectj.lang.ProceedingJoinPoint
;
import
org.aspectj.lang.ProceedingJoinPoint
;
import
org.aspectj.lang.annotation.Around
;
import
org.aspectj.lang.annotation.Around
;
import
org.aspectj.lang.annotation.Aspect
;
import
org.aspectj.lang.annotation.Aspect
;
...
@@ -8,6 +8,7 @@ import org.aspectj.lang.annotation.Pointcut;
...
@@ -8,6 +8,7 @@ import org.aspectj.lang.annotation.Pointcut;
import
org.aspectj.lang.reflect.MethodSignature
;
import
org.aspectj.lang.reflect.MethodSignature
;
import
org.slf4j.Logger
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.core.annotation.AnnotationUtils
;
import
org.springframework.core.annotation.Order
;
import
org.springframework.core.annotation.Order
;
import
org.springframework.stereotype.Component
;
import
org.springframework.stereotype.Component
;
import
com.ruoyi.common.utils.StringUtils
;
import
com.ruoyi.common.utils.StringUtils
;
...
@@ -60,17 +61,12 @@ public class DataSourceAspect
...
@@ -60,17 +61,12 @@ public class DataSourceAspect
public
DataSource
getDataSource
(
ProceedingJoinPoint
point
)
public
DataSource
getDataSource
(
ProceedingJoinPoint
point
)
{
{
MethodSignature
signature
=
(
MethodSignature
)
point
.
getSignature
();
MethodSignature
signature
=
(
MethodSignature
)
point
.
getSignature
();
Class
<?
extends
Object
>
targetClass
=
point
.
getTarget
().
getClass
();
DataSource
dataSource
=
AnnotationUtils
.
findAnnotation
(
signature
.
getMethod
(),
DataSource
.
class
);
DataSource
targetDataSource
=
targetClass
.
getAnnotation
(
DataSource
.
class
);
if
(
Objects
.
nonNull
(
dataSource
))
if
(
StringUtils
.
isNotNull
(
targetDataSource
))
{
{
return
targetDataSource
;
}
else
{
Method
method
=
signature
.
getMethod
();
DataSource
dataSource
=
method
.
getAnnotation
(
DataSource
.
class
);
return
dataSource
;
return
dataSource
;
}
}
return
AnnotationUtils
.
findAnnotation
(
signature
.
getDeclaringType
(),
DataSource
.
class
);
}
}
}
}
ruoyi/src/main/java/com/ruoyi/framework/aspectj/lang/annotation/DataSource.java
View file @
41799c10
...
@@ -10,7 +10,9 @@ import com.ruoyi.framework.aspectj.lang.enums.DataSourceType;
...
@@ -10,7 +10,9 @@ import com.ruoyi.framework.aspectj.lang.enums.DataSourceType;
/**
/**
* 自定义多数据源切换注解
* 自定义多数据源切换注解
*
*
* 优先级:先方法,后类,如果方法覆盖了类上的数据源类型,以方法的为准,否则以类上的为准
*
* @author ruoyi
* @author ruoyi
*/
*/
@Target
({
ElementType
.
METHOD
,
ElementType
.
TYPE
})
@Target
({
ElementType
.
METHOD
,
ElementType
.
TYPE
})
...
...
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