MybatisPlus 分页插件导致@InterceptorIgnore(tenantLine = “true”)注解失效的原因在于分页插件SQL执行顺序问题.
比如下面这个分页查询方法
分页插件在处理的时候会先执行 com.xx.system.mapper.SysEnterpriseBindingMapper.listPage_COUNT
当返回count只大于0 ,才会继续执行 com.xx.system.mapper.SysEnterpriseBindingMapper.listPage
但是在 InterceptorIgnoreHelper.INTERCEPTOR_IGNORE_CACHE
中存的是方法没有 _COUNT
后缀的这个方法(com.xx.system.mapper.SysEnterpriseBindingMapper.listPage
)所以导致 willIgnoreTenantLine
方法中的参数id=com.xx.system.mapper.SysEnterpriseBindingMapper.listPage_COUNT
在INTERCEPTOR_IGNORE_CACHE
匹配不到对应的,所以就返回false,从而导致了@InterceptorIgnore(tenantLine = "true")
失效,源码如下:
解决方案:
在原有的分页查询方法的mapper接口中,手动添加一个com.xx.system.mapper.SysEnterpriseBindingMapper.listPage_COUNT
方法并且在方法上添加 @InterceptorIgnore(tenantLine = "true")
注解,这样的话在willIgnoreTenantLine()
方法中就能够匹配到.并且该方法无需在xml中写真是sql,只需要添加这么一个伪方法,然后mybatisplu将这个方法存到InterceptorIgnoreHelper
类中的INTERCEPTOR_IGNORE_CACHE
的 Map中可以