当前使用版本(必填,否则不予处理)
3.4.3
该问题是如何引起的?(确定最新版也有问题再提!!!)
1.MybatisPlusInterceptor 添加数据权限插件DataPermissionInterceptor 2.com.baomidou.mybatisplus.extension.plugins.inner.DataPermissionInterceptor#beforeQuery 3.判断条件 if (InterceptorIgnoreHelper.willIgnoreDataPermission(ms.getId())) return; 4. InterceptorIgnoreCache cache = INTERCEPTOR_IGNORE_CACHE.get(id); 如果cache为空,即如果mapper不加 InterceptorIgnore 默认就会走这个插件
重现步骤(如果有就写完整)
报错信息
Comment From: VampireAchao
最新版可配置
@InterceptorIgnore(dataPermission=“false”)
Comment From: wenyang8023
@Override
public void beforeQuery(Executor executor, MappedStatement ms, Object parameter, RowBounds rowBounds, ResultHandler resultHandler, BoundSql boundSql) throws SQLException {
if (InterceptorIgnoreHelper.willIgnoreDataPermission(ms.getId())) return;
PluginUtils.MPBoundSql mpBs = PluginUtils.mpBoundSql(boundSql);
mpBs.sql(parserSingle(mpBs.sql(), ms.getId()));
}
public static boolean willIgnore(String id, Function<InterceptorIgnoreCache, Boolean> function) {
InterceptorIgnoreCache cache = INTERCEPTOR_IGNORE_CACHE.get(id);
if (cache == null) {
cache = INTERCEPTOR_IGNORE_CACHE.get(id.substring(0, id.lastIndexOf(StringPool.DOT)));
}
if (cache != null) {
Boolean apply = function.apply(cache);
return apply != null && apply;
}
return false;
}
/**
* 初始化缓存
* <p>
* Mapper 上 InterceptorIgnore 注解信息
*
* @param mapperClass Mapper Class
*/
public synchronized static InterceptorIgnoreCache initSqlParserInfoCache(Class<?> mapperClass) {
InterceptorIgnore ignore = mapperClass.getAnnotation(InterceptorIgnore.class);
if (ignore != null) {
String key = mapperClass.getName();
InterceptorIgnoreCache cache = buildInterceptorIgnoreCache(key, ignore);
INTERCEPTOR_IGNORE_CACHE.put(key, cache);
return cache;
}
return null;
}
如果mapper上 不加 @InterceptorIgnore注解 ,beforeQuery方法会继续往下执行 然后所有的mapper不可能都去加这个注解,这样成本太高
Comment From: uncarbon97
可能临时方案的话,只能自己复制源码,重新实现一个InnerInterceptor,然后加入InnerInterceptor链中了
Comment From: wenyang8023
我临时方案是直接继承了DataPermissionInterceptor插件,重写了beforeQuery方法
Comment From: qmdx
忽略注解有一个 other 也是可以用的,自己根据判断处理,新版本会支持 threadlocal 方式控制