use of com.baomidou.mybatisplus.extension.plugins.inner.TenantLineInnerInterceptor in project jeecg-boot by jeecgboot.
the class MybatisPlusSaasConfig method mybatisPlusInterceptor.
@Bean
public MybatisPlusInterceptor mybatisPlusInterceptor() {
MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
// 先 add TenantLineInnerInterceptor 再 add PaginationInnerInterceptor
interceptor.addInnerInterceptor(new TenantLineInnerInterceptor(new TenantLineHandler() {
@Override
public Expression getTenantId() {
String tenant_id = oConvertUtils.getString(TenantContext.getTenant(), "0");
return new LongValue(tenant_id);
}
@Override
public String getTenantIdColumn() {
return TENANT_FIELD_NAME;
}
// 返回 true 表示不走租户逻辑
@Override
public boolean ignoreTable(String tableName) {
for (String temp : tenantTable) {
if (temp.equalsIgnoreCase(tableName)) {
return false;
}
}
return true;
}
}));
interceptor.addInnerInterceptor(new PaginationInnerInterceptor());
return interceptor;
}
use of com.baomidou.mybatisplus.extension.plugins.inner.TenantLineInnerInterceptor in project ieasy-server by baayso.
the class MybatisPlusConfig method mybatisPlusInterceptor.
/**
* mybatis-plus 插件
* <p>
* 文档:https://baomidou.com/pages/2976a3/
* <p>
* 使用多个功能需要注意顺序关系,建议使用如下顺序<br>
* 1) 多租户,动态表名<br>
* 2) 分页,乐观锁<br>
* 3) sql 性能规范,防止全表更新与删除<br>
* 总结: 对 sql 进行单次改造的优先放入,不对 sql 进行改造的最后放入
*/
@Bean
public MybatisPlusInterceptor mybatisPlusInterceptor() {
MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
// 防止全表更新与删除插件
interceptor.addInnerInterceptor(new BlockAttackInnerInterceptor());
// 多租户插件
TenantLineInnerInterceptor tenantLineInnerInterceptor = new TenantLineInnerInterceptor();
// 行级租户SQL解析器
tenantLineInnerInterceptor.setTenantLineHandler(new BasicTenantLineHandler());
interceptor.addInnerInterceptor(tenantLineInnerInterceptor);
// 分页插件
// 如果使用了分页插件注意先 add TenantLineInnerInterceptor 再 add PaginationInnerInterceptor
interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL));
// 乐观锁插件
interceptor.addInnerInterceptor(new OptimisticLockerInnerInterceptor());
return interceptor;
}
use of com.baomidou.mybatisplus.extension.plugins.inner.TenantLineInnerInterceptor in project XHuiCloud by sindaZeng.
the class XHuiMybatisPlusConfig method mybatisPlusInterceptor.
/**
* 数据处理
*/
/**
* mybatis plus 拦截器配置
* @return
*/
@Bean
public MybatisPlusInterceptor mybatisPlusInterceptor(XHuiTenantHandler xHuiTenantHandler) {
MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
// 多租户支持
TenantLineInnerInterceptor tenantLineInnerInterceptor = new TenantLineInnerInterceptor();
tenantLineInnerInterceptor.setTenantLineHandler(xHuiTenantHandler);
interceptor.addInnerInterceptor(tenantLineInnerInterceptor);
interceptor.addInnerInterceptor(new PaginationInnerInterceptor());
return interceptor;
}
use of com.baomidou.mybatisplus.extension.plugins.inner.TenantLineInnerInterceptor in project ruoyi-vue-pro by YunaiV.
the class YudaoTenantAutoConfiguration method tenantLineInnerInterceptor.
// ========== DB ==========
@Bean
public TenantLineInnerInterceptor tenantLineInnerInterceptor(TenantProperties properties, MybatisPlusInterceptor interceptor) {
TenantLineInnerInterceptor inner = new TenantLineInnerInterceptor(new TenantDatabaseInterceptor(properties));
// 添加到 interceptor 中
// 需要加在首个,主要是为了在分页插件前面。这个是 MyBatis Plus 的规定
MyBatisUtils.addInterceptor(interceptor, inner, 0);
return inner;
}
use of com.baomidou.mybatisplus.extension.plugins.inner.TenantLineInnerInterceptor in project helio-starters by uncarbon97.
the class TenantLineSupport method support.
@Override
public void support(HelioProperties helioProperties, MybatisPlusInterceptor interceptor) {
Collection<String> ignoredTables = helioProperties.getTenant().getIgnoredTables();
// 添加行级租户内联拦截器
interceptor.addInnerInterceptor(new TenantLineInnerInterceptor(new HelioLineTenantHandler(helioProperties.getTenant().getPrivilegedTenantId(), ignoredTables)));
log.info("\n\n[多租户支持] >> 隔离级别: 行级");
System.err.println("以下数据表不参与租户隔离: " + ignoredTables);
}
Aggregations