当前使用版本(必填,否则不予处理)
mybatis-plus 3.4.0
该问题是如何引起的?(确定最新版也有问题再提!!!)
重现步骤(如果有就写完整)
/**
* 新多租户插件配置,一缓和二缓遵循mybatis的规则,
* 需要设置 MybatisConfiguration#useDeprecatedExecutor = false
* 避免缓存万一出现问题
* @return
*/
@Bean
public TenantLineInnerInterceptor tenantLineInnerInterceptor(){
return new TenantLineInnerInterceptor(new TenantLineHandler() {
/**
* 获取租户ID
* @return
*/
@Override
public Expression getTenantId() {
String customerId = SecurityUtil.getCustomerId();
if (customerId != null) {
return new StringValue(customerId);
}
return new NullValue();
}
/**
* 获取多租户的字段名
* @return String
*/
@Override
public String getTenantIdColumn() {
return "customer_id";
}
/**
* 过滤不需要根据租户隔离的表
* 这是 default 方法,默认返回 false 表示所有表都需要拼多租户条件
* @param tableName 表名
*/
@Override
public boolean ignoreTable(String tableName) {
return tenantProperties.getIgnoreTables().stream().anyMatch(
(t) -> t.equalsIgnoreCase(tableName)
);
}
});
}
下面这个是写的方法不加多租户条件
@InterceptorIgnore //跳过多租户
List
打印的sql日志还是包含 自定义的多租户字段(customer_id)
SELECT id, mail_no, amount, actual_amount, delivery_date, receive_date, express_message, remark, sort, create_user, create_dept, create_time, update_user, update_time, STATUS, is_deleted, customer_id FROM express WHERE is_deleted = 0 AND receive_date IS NULL AND customer_id = ''
Comment From: miemieYaho
https://mybatis.plus/guide/interceptor.html#%E4%BD%BF%E7%94%A8%E6%96%B9%E5%BC%8F-%E4%BB%A5%E5%88%86%E9%A1%B5%E6%8F%92%E4%BB%B6%E4%B8%BE%E4%BE%8B
Comment From: Wsinry
解决了吗?我目前也碰到这个问题,望解答,谢谢
Comment From: uncarbon97
注解上要加东西呀…… @InterceptorIgnore(tenantLine = "true")