異常內容:
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