use of com.github.lybgeek.mybatisplus.tenant.parser.CustomTenantSqlParser in project springboot-learning by lyb-geek.
the class MyBatisPlusTenantConfig method tenantHandler.
/**
* 租户处理
* @param paginationInterceptor
*/
private void tenantHandler(PaginationInterceptor paginationInterceptor) {
// 创建SQL解析器集合
List<ISqlParser> sqlParserList = new ArrayList<>();
// 创建租户SQL解析器
TenantSqlParser tenantSqlParser = new CustomTenantSqlParser();
// 设置租户处理器
tenantSqlParser.setTenantHandler(new TenantHandler() {
@Override
public Expression getTenantId() {
return new LongValue(100);
}
@Override
public String getTenantIdColumn() {
// 对应数据库租户ID的列名
return "tenant_id";
}
@Override
public boolean doTableFilter(String tableName) {
List<String> skipFillTenantIdTables = myBatisPlusTenantProperties.getSkipFillTenantIdTables();
return skipFillTenantIdTables.contains(tableName);
}
});
sqlParserList.add(tenantSqlParser);
paginationInterceptor.setSqlParserList(sqlParserList);
}
Aggregations