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 里,需用专门工具才能看到里面.就是个数据库,里面有很多表. ...
随机推荐
- moviepy音视频剪辑:视频半自动追踪人脸打马赛克
一.引言 在<moviepy1.03音视频剪辑:使用manual_tracking和headblur实现追踪人脸打马赛克>介绍了使用手动跟踪跟踪人脸移动轨迹和使用headblur对人脸进行 ...
- 第15.43节、PyQt输入部件:QAbstractSpinBox派生类QSpinBox、 QDoubleSpinBox、QDateTimeEdit、QDateEdit和QTimeEdit功能简介
专栏:Python基础教程目录 专栏:使用PyQt开发图形界面Python应用 专栏:PyQt入门学习 老猿Python博文目录 老猿学5G博文目录 一.概述 Designer输入部件中的Spin B ...
- PyQt(Python+Qt)学习随笔:QAbstractItemView的selectionMode属性
老猿Python博文目录 老猿Python博客地址 一.概述 selectionMode属性用于控制view中操作选择数据项的模式,用于控制用户是否可以选择一个或多个数据项,以及在多个数据项选择中,选 ...
- PyQt(Python+Qt)学习随笔:Qt Designer中主窗口对象unifiedTitleAndToolBarOnMac属性
unifiedTitleAndToolBarOnMac 用于确认在mac操作系统上是否使用统一的标题和工具栏外观 有如下几个限制: 1.不支持使用带OpenGl内容的窗口,包括QGLWidget 和 ...
- c++11-17 模板核心知识(十五)—— 解析模板之依赖型类型名称与typename Dependent Names of Types
模板名称的问题及解决 typename规则 C++20 typename 上篇文章c++11-17 模板核心知识(十四)-- 解析模板之依赖型模板名称 Dependent Names of Templ ...
- 「IOI2017」接线 的另类做法
看到这题,我的第一反应是:这就是一个费用流模型?用模拟费用流的方法? 这应该是可以的,但是我忘记了怎么模拟费用流了IOI不可能考模拟费用流.于是我就想了另外一个方法. 首先我们考虑模拟费用流的模型如下 ...
- 算法—— n个骰子的点数
把n个骰子扔在地上,所有骰子朝上一面的点数之和为s.输入n,打印出s的所有可能的值出现的概率. 你需要用一个浮点数数组返回答案,其中第 i 个元素代表这 n 个骰子所能掷出的点数集合中第 i 小的那个 ...
- sql server添加单独新用户
- .net5+nacos+ocelot 配置中心和服务发现实现
最近一段时间 因公司业务需要,需要使用.net5做一套微服务的接口,使用nacos 做注册中心和配置中心,ocelot做网关. 因为ocelot 支持的是consol和eureka,如果使用nacos ...
- Windows 必备——cmder 一款比cmd牛逼的Win软件
Windows 必备--cmder 一款比cmd牛逼的Win软件一款Windows环境下的命令行替换工具:cmder这款工具简洁美观易用,支持大部分的linux命令,支持ssh连接Linux,比起自带 ...