baomidou / mybatis-plus

An powerful enhanced toolkit of MyBatis for simplify development
https://baomidou.com
Apache License 2.0
16.3k stars 4.3k forks source link

mapper上使用InterceptorIgnore注解,但是pagehelper的count查询不能取消租户注入 #5167

Closed xukaisjz closed 1 year ago

xukaisjz commented 1 year ago

当前使用版本(必填,否则不予处理)

mybatis-plus版本:3.4.2 pagehelper版本:1.4.3

该问题是如何引起的?(确定最新版也有问题再提!!!)

在mapper方法上添加InterceptorIgnore取消租户注入行为 在mapper方法前使用了pagehelper的startPage方法,在执行count查询时会注入租户查询条件

重现步骤(如果有就写完整)

startPage() baseMapper.selectPageListByCondition(params);

报错信息

miemieYaho commented 1 year ago

把他的分页插件放到mp的插件后面

xukaisjz commented 1 year ago

把他的分页插件放到mp的插件后面

像这样? @bean public MybatisPlusInterceptor mybatisPlusInterceptor() { MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor(); // 多租户 interceptor.addInnerInterceptor(tenantLineInnerInterceptor()); // 分页插件 interceptor.addInnerInterceptor(paginationInnerInterceptor()); // 乐观锁插件 interceptor.addInnerInterceptor(optimisticLockerInnerInterceptor()); // 阻断插件 interceptor.addInnerInterceptor(blockAttackInnerInterceptor()); return interceptor; }

miemieYaho commented 1 year ago

你不是用pagehelper吗?@Bean他的插件到mp的插件的所在代码行数的后面

zldaysleepy commented 10 months ago

我也遇到了,请问有好的解决方案吗

xukaisjz commented 10 months ago

自定义一个注解,通过设置标记,在租户注入那里增加标记判断,可以用Threadlocal添加一个变量标记

2023年11月13日 16:29,zldaysleepy @.***> 写道:

我也遇到了,请问有好的解决方案吗

— Reply to this email directly, view it on GitHub https://github.com/baomidou/mybatis-plus/issues/5167#issuecomment-1807669804, or unsubscribe https://github.com/notifications/unsubscribe-auth/AQHHNXFGTI2WJTTC7TYTRSDYEHLAJAVCNFSM6AAAAAAVJIVAVGVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQMBXGY3DSOBQGQ. You are receiving this because you authored the thread.

qichhhhh commented 4 months ago

你不是用pagehelper吗?@Bean他的插件到mp的插件的所在代码行数的后面

@miemieYaho 你好,我也遇到了这个问题,@Bean 的声明顺序是这样的,但是在 PageHelper 的 COUNT 的语句还是把 tenant_id 拼接了 image image

image

zldaysleepy commented 4 months ago

你放反了,PageInterceptor需要在前面,因为先注入的后执行

qichhhhh commented 4 months ago

你放反了,PageInterceptor需要在前面,因为先注入的后执行

谢谢大哥,可以了