2
2
3
3
import com .baomidou .mybatisplus .extension .plugins .MybatisPlusInterceptor ;
4
4
import com .baomidou .mybatisplus .extension .plugins .inner .DataPermissionInterceptor ;
5
+ import com .github .cadecode .uniboot .common .plugin .mybatis .aspect .DataScopeAspect ;
6
+ import com .github .cadecode .uniboot .common .plugin .mybatis .aspect .DataScopeAspect .DataScopeParam ;
5
7
import com .github .cadecode .uniboot .common .plugin .mybatis .handler .DataScopePermissionHandler ;
8
+ import org .apache .ibatis .executor .Executor ;
9
+ import org .apache .ibatis .mapping .BoundSql ;
10
+ import org .apache .ibatis .mapping .MappedStatement ;
11
+ import org .apache .ibatis .session .ResultHandler ;
12
+ import org .apache .ibatis .session .RowBounds ;
6
13
import org .springframework .context .annotation .Bean ;
7
14
import org .springframework .context .annotation .Configuration ;
8
15
16
+ import java .sql .SQLException ;
17
+ import java .util .Objects ;
18
+
9
19
/**
10
20
* mybatis 配置类
11
21
*
@@ -22,7 +32,17 @@ public class MybatisConfig {
22
32
public MybatisPlusInterceptor mybatisPlusInterceptor () {
23
33
MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor ();
24
34
// 数据权限插件
25
- DataPermissionInterceptor dataPermissionInterceptor = new DataPermissionInterceptor (new DataScopePermissionHandler ());
35
+ DataPermissionInterceptor dataPermissionInterceptor = new DataPermissionInterceptor (new DataScopePermissionHandler ()) {
36
+ @ Override
37
+ public void beforeQuery (Executor executor , MappedStatement ms , Object parameter , RowBounds rowBounds , ResultHandler resultHandler , BoundSql boundSql ) throws SQLException {
38
+ // 没有使用注解时,跳过
39
+ DataScopeParam dataScopeParam = DataScopeAspect .currDataScope ();
40
+ if (Objects .isNull (dataScopeParam ) || !dataScopeParam .isEnableFilter ()) {
41
+ return ;
42
+ }
43
+ super .beforeQuery (executor , ms , parameter , rowBounds , resultHandler , boundSql );
44
+ }
45
+ };
26
46
interceptor .addInnerInterceptor (dataPermissionInterceptor );
27
47
28
48
// 添加分页插件,动态获取数据库类型
0 commit comments