Failed to process, please exclude the tableName or statementId.--Mybatis-Plus
多租户
多个用户间使用同一套程序,但每个用户之间实现数据隔离
方法一
:在 Mapper 的自定义方法上添加注解 @SqlParser(filter = true),在查询的时候不需要添加租户信息
@SqlParser(filter=true)
IPage<CognitiveCardPackagePageData> selectCognitiveCardPackagePage(Page page,@Param("query") OkyaCognitiveCardPackagePageListQueryData req);
方法二
@Slf4j
@Configuration
@MapperScan(value = {"com.**.dao"})
public class MyBatisPlusConfig {
/**
* 分页插件
*/
@Bean
public PaginationInterceptor paginationInterceptor(DynamicTableNameParser dynamicTableNameParser) {
PaginationInterceptor paginationInterceptor = new PaginationInterceptor();
List<ISqlParser> sqlParserList = new ArrayList<>();
// 添加租户sql解析链,如果是开发业务系统,可以去掉这个配置,不去也可以。
TenantSqlParser tenantSqlParser = new TenantSqlParser();
tenantSqlParser.setTenantHandler(tenantHandler());
sqlParserList.add(tenantSqlParser);
// 设置sql解析链
paginationInterceptor.setSqlParserList(sqlParserList);
// 设置过滤器链
paginationInterceptor.setSqlParserFilter(sqlParserFilter());
return paginationInterceptor;
}
@Bean
public TenantHandler tenantHandler() {
return new TenantHandler() {
@Override
public Expression getTenantId() {
// 返回当前登录人员的租户ID
return new LongValue(
RbacUserUtils.getCurrentTenantId());
}
@Override
public String getTenantIdColumn() {
return "tenant_id";
}
@Override
public boolean doTableFilter(String tableName) {
return false;
}
};
}
/**
* 如何有自定义无租户的查询,可以在此过滤
* @return SQL解析过滤
*/
@Bean
public ISqlParserFilter sqlParserFilter() {
return metaObject -> {
// 如果在程序中已经手动设置了tenant_id,此处就过滤
Object boundSql = metaObject.getValue("boundSql");
String sql = String.valueOf(ReflectionUtils
.getFieldValue(boundSql, "sql"));
return StringUtils.containsIgnoreCase(sql, "insert")
&& StringUtils.containsIgnoreCase(sql, "tenant_id");
};
}
}
注意此处的sqlParserFilter的配置,在没有此配置之前,无论你是插入、更新、查询,mybatis plus 就带上tenant_id,这个tenant_id不是一直都是有的,在注册租户的时候就是没有的,不过这也没有关系,我们可以当系统当前没有登录的租户时就将租户的ID统一设置为-1(一个统一特殊的数值),有登录的用户就获取该用户的租户ID获租户自己的ID。这是没有问题的。
Failed to process, please exclude the tableName or statementId.--Mybatis-Plus的更多相关文章
- Cleanup failed to process the following paths错误的解决
在使用TortoiseSVN工具执行Cleanup操作时经常出现Cleanup failed to process the following paths的错误,具体如下图: 网上搜索了一下,找到了解 ...
- SVN Cleanup failed to process the following paths错误的解决
在使用TortoiseSVN工具执行Cleanup操作时经常出现Cleanup failed to process the following paths的错误,具体如下图: 网上搜索了一下,找到了解 ...
- svn-clearup 报错的处理(Cleanup failed to process the following paths...)
在使用 svn 客户端执行操作失败后,执行 Clean up 操作也报错:Cleanup failed to process the following paths... ,一直不知道是什么原因.通常 ...
- 解决SVN Cleanup时遇到错误信息:Cleanup failed to process the following paths:xxxxxxx Previous operation has not finished: run 'cleanup' if it was interrupted Please execute the 'Cleanup' command.
解决SVN Cleanup时遇到错误信息:Cleanup failed to process the following paths:xxxxxxx Previous operation has no ...
- WebHost failed to process a request.Memory gates checking failed because the free memory (140656640 bytes) is less than 5% of total memory
WebHost failed to process a request. Sender Information: System.ServiceModel.ServiceHostingEnvironme ...
- react native报错处理com.android.build.api.transform.TransformException: com.android.builder.dexing.DexArchiveBuilderException: com.android.builder.dexing.DexArchiveBuilderException: Failed to process
背景:最近准备在使用react-native开发的app中接入友盟,来进行用户行为统计,分享,授权登录等操作. 在使用的过程中,遇到了一些错误信息,在此记录一下. 在修改android目录下的buil ...
- SVN 执行cleanup报错:Cleanup failed to process the following paths
SVN 执行cleanup报错:Cleanup failed to process the following paths 先来说下这个错误的原因:用SVN在使用过程中,各种原因中途取消或中断,导致需 ...
- SMTP Failed on Process Scheduler
If you are seeing messages like this in your message log when running a process through the process ...
- SVN:Cleanup failed to process the following paths
频繁使用SVN,于是乎玩坏了.用了一下clearup,结果爆了如题错误.查了一下,是有文件被加锁了,位置在项目根目录 .svn下的wc.db 里,需用专门工具才能看到里面.就是个数据库,里面有很多表. ...
随机推荐
- Jmeter(三十) - 从入门到精通 - Jmeter Http协议录制脚本工具-Badboy3(详解教程)
1.简介 Badboy为方便自动化数据灵活性,以及脚本的重用,减少工作量:为此提供了脚本参数化的功能,这一篇文章宏哥以度娘搜索的关键字"北京-宏哥"进行参数化为例,宏哥带领你们实战 ...
- sqli-labs-master less06
第六关与第五关步骤无区别,请参考 sqli-labs-master less05 及 Burp Suite暴力破解示例 区别:在第二步判断注入类型时发现 加单引号与不加单引号没有区别,加双引号时报错, ...
- jdk从1.8降到jdk1.7失败
1.将JAVA_HOME:的路径更改为1.7的相关路径,例如我的:C:\Java\jdk1.7.0_80 2.此时查看版本:Java -version,如果是1.8的版本,就把path路径下的%JAV ...
- 网络最大流 Dinic算法
前言 看到网上好多都用的链式前向星,就我在用 \(vector\) 邻接表-- 定义 先来介绍一些相关的定义.(个人理解) 网络 一个网络是一张带权的有向图 \(G=(V,E)\) ,其中每任意一条边 ...
- charles功能(三)弱网测试(模拟超慢网速,会导致接口数据返回超时的那种慢)
模拟超慢网速(会导致接口数据返回超时的那种...) 设置带宽和延迟时间(毫秒) 注:可以根据下图中的翻译体会下导致网络延迟的原因: 然后打开网页回变得非常满
- PyQt开发样例: 利用QToolBox开发的桌面工具箱Demo
老猿Python博文目录 专栏:使用PyQt开发图形界面Python应用 老猿Python博客地址 一.引言 toolBox工具箱是一个容器部件,对应类为QToolBox,在其内有一列从上到下顺序排列 ...
- 谈谈传说中的redo log是什么?有啥用?
目录 一.引出 redo log 的作用 二.思考一个问题: 三.redo log block 四.redo log buffer 五.redo log的刷盘时机 六.推荐参数 七.redo log ...
- 代码审计系列题目CTFD部署(上)
关于简单部署题目请参考:https://www.cnblogs.com/Cl0ud/p/13783325.html 如果需要进行较复杂部署,可参考本篇 PHP代码审计系列题目的部署,较之前的部署方案, ...
- win10系统rational rose 安装后打开弹框显示java.lang.ClassNotFoundException 解决方案
场景复现:安装Rational Rose,按照破解方法完成后,打开程序,会弹出对话框显示java.lang.ClassNotFoundException,在关闭程序时也会弹出一个对话框,并且程序不能关 ...
- 模拟数组 push() 方法
var array =[]; Array.prototype.push = function (){ for (var i=0; i< arguments.length; i++){ this[ ...