Mybatis Plus使用租户过滤无效解决方案

异常内容:

org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.exceptions.PersistenceException:
### Error updating database. Cause: java.lang.NullPointerException
### The error may exist in file [xxxxx.xml]
### The error may involve xxxxxxx
### The error occurred while executing an update
### Cause: java.lang.NullPointerException
at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:92)
at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:440)
at com.sun.proxy.$Proxy121.insert(Unknown Source)
at org.mybatis.spring.SqlSessionTemplate.insert(SqlSessionTemplate.java:271)
at com.baomidou.mybatisplus.core.override.MybatisMapperMethod.execute(MybatisMapperMethod.java:60)

 

---

### The error occurred while executing an update
### Cause: com.baomidou.mybatisplus.core.exceptions.MybatisPlusException: Failed to process, please exclude the tableName or statementId.

 解决方法加上 

@SqlParser(filter = true)  注解即可

 

 

 

默认mybatis plus和mysql是不支持多语句处理的;需要配置2个地方:

第一处就是数据库的链接追加上此参数:&allowMultiQueries=true

官方文档:https://dev.mysql.com/doc/connector-j/8.0/en/connector-j-connp-props-security.html#cj-conn-prop_allowMultiQueries

 

 

第二处就是数据源:我使用的是Druid数据源;那么需要配置  spring.datasource.dynamic.druid.wall.multi-statement-allow=true  即可

文档:https://github.com/alibaba/druid/wiki/%E9%85%8D%E7%BD%AE-wallfilter

 

 

 

Mybatis Plus:https://mybatis.plus/guide/interceptor-tenant-line.html

 

常见的问题:

MybatisPlus多租户表;当配置 这个后 :com.baomidou.mybatisplus.extension.plugins.tenant.TenantHandler#doTableFilter;对应的mapper文件中的表名不能包含 ``反引号;因为 

 

 

这里的代码会返回false,不会过滤 ;对应的位置:com.baomidou.mybatisplus.extension.plugins.tenant.TenantSqlParser#processInsert

 

 

 

 
posted @ 2021-06-11 10:08  星小梦  阅读(3323)  评论(0编辑  收藏  举报