Skip to content

Commit

Permalink
feat(mybatis-plus-boot-starter): 添加租户开关配置,默认关
Browse files Browse the repository at this point in the history
  • Loading branch information
andanyoung committed Nov 14, 2023
1 parent f93885d commit e6f0bc9
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 11 deletions.
2 changes: 1 addition & 1 deletion admin4j-dependencies/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@
<dependency>
<groupId>com.admin4j.framework</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>${admin4j.version}</version>
<version>0.9.3-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.admin4j.framework</groupId>
Expand Down
3 changes: 2 additions & 1 deletion mybatis-plus-boot-starter/pom.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
Expand All @@ -12,6 +12,7 @@
<packaging>jar</packaging>

<name>mybatis-plus-boot-starter</name>
<version>0.9.3-SNAPSHOT</version>


<properties>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public void setLoginTenantInfoService(ILoginTenantInfoService loginTenantInfoSer
this.loginTenantInfoService = loginTenantInfoService;
}

//多租户
// 多租户
public TenantLineInnerInterceptor tenantLineInnerInterceptor(ILoginTenantInfoService loginTenantInfoService) {

return new TenantLineInnerInterceptor(new TenantLineHandler() {
Expand All @@ -55,7 +55,7 @@ public Expression getTenantId() {
public boolean ignoreTable(String tableName) {

Long tenantId = loginTenantInfoService.getTenantId();
//没有登录,可关闭 租户
// 没有登录,可关闭 租户
if (ObjectUtils.isEmpty(tenantId) || Objects.equals(0L, tenantId)) {
return true;
}
Expand All @@ -77,22 +77,22 @@ public boolean ignoreTable(String tableName) {
public MybatisPlusInterceptor mybatisPlusInterceptor() {
MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();

if (loginTenantInfoService != null) {
if (loginTenantInfoService != null && mpProperties.isTenantEnable()) {
interceptor.addInnerInterceptor(tenantLineInnerInterceptor(loginTenantInfoService));
}


//分页插件
// 分页插件
interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL));
//乐观锁
// 乐观锁
interceptor.addInnerInterceptor(new OptimisticLockerInnerInterceptor());
//防止全表更新与删除
// 防止全表更新与删除
interceptor.addInnerInterceptor(new BlockAttackInnerInterceptor());

//动态表名
//interceptor.addInnerInterceptor(new DynamicTableNameInnerInterceptor());
// 动态表名
// interceptor.addInnerInterceptor(new DynamicTableNameInnerInterceptor());

//sql 性能规范
// sql 性能规范
if (mpProperties.isIllegalSql()) {
interceptor.addInnerInterceptor(new IllegalSQLInnerInterceptor());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,16 @@
@ConfigurationProperties(prefix = "admin4j.mp")
public class MpProperties {

/**
* 多租户功能开关
*/
private boolean tenantEnable = false;

/**
* 多租需要忽略的表
*/
private String[] ignoreTenantTable;

/**
* 是否开启 sql 性能规范插件
*/
Expand Down

0 comments on commit e6f0bc9

Please sign in to comment.