add
This commit is contained in:
@ -1,5 +1,6 @@
|
||||
package com.qiaoba.common.database.config;
|
||||
|
||||
import cn.hutool.core.collection.ListUtil;
|
||||
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
|
||||
import com.baomidou.mybatisplus.extension.plugins.handler.TenantLineHandler;
|
||||
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
|
||||
@ -10,6 +11,8 @@ import net.sf.jsqlparser.expression.StringValue;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* MybatisPlusConfig
|
||||
*
|
||||
@ -20,6 +23,11 @@ import org.springframework.context.annotation.Configuration;
|
||||
@Configuration
|
||||
public class MybatisPlusConfig {
|
||||
|
||||
/**
|
||||
* 不需要拼接租户ID的表 租户表/租户数据源表
|
||||
*/
|
||||
private static final List<String> IGNORE_TABLES = ListUtil.toList("sys_tenant", "sys_tenant_datasource");
|
||||
|
||||
@Bean
|
||||
public MybatisPlusInterceptor mybatisPlusInterceptor() {
|
||||
MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
|
||||
@ -29,10 +37,10 @@ public class MybatisPlusConfig {
|
||||
return new StringValue(BaseContext.getTenantId());
|
||||
}
|
||||
|
||||
// sys_tenant 不需要拼接租户ID
|
||||
// 不拼接租户ID
|
||||
@Override
|
||||
public boolean ignoreTable(String tableName) {
|
||||
return "sys_tenant".equals(tableName);
|
||||
return IGNORE_TABLES.contains(tableName);
|
||||
}
|
||||
}));
|
||||
interceptor.addInnerInterceptor(new PaginationInnerInterceptor());
|
||||
|
@ -23,7 +23,7 @@ public class PoolInfo {
|
||||
private Integer min;
|
||||
|
||||
/**
|
||||
* 最大空闲数
|
||||
* 最大连接数
|
||||
*/
|
||||
private Integer max;
|
||||
}
|
||||
|
@ -1,5 +1,9 @@
|
||||
package com.qiaoba.common.database.utils;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.qiaoba.common.base.exceptions.ServiceException;
|
||||
import com.qiaoba.common.web.advice.ExceptionAdvice;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.SQLException;
|
||||
@ -52,9 +56,9 @@ public class JdbcUtil {
|
||||
Class.forName(driver);
|
||||
//建立连接
|
||||
conn = DriverManager.getConnection(url, username, password);
|
||||
return conn;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
throw new ServiceException(StrUtil.format("数据源连接失败,错误: {}", e.getMessage()));
|
||||
}
|
||||
return conn;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user