提交 b8d57679 编写于 作者: xignzi006's avatar xignzi006 🇨🇳

更新 MybatisConfiguration.java.ftl

上级 a8dacde5
...@@ -15,10 +15,14 @@ import org.apache.ibatis.mapping.VendorDatabaseIdProvider; ...@@ -15,10 +15,14 @@ import org.apache.ibatis.mapping.VendorDatabaseIdProvider;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.mybatis.spring.annotation.MapperScan; import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Autowired;
import java.util.Properties; import java.util.Properties;
<#if sys.getSaaSMode()==2> <#if sys.getSaaSMode()==2>
import com.baomidou.mybatisplus.core.parser.ISqlParserFilter;
import com.baomidou.mybatisplus.core.parser.SqlParserHelper;
import com.baomidou.mybatisplus.extension.plugins.tenant.TenantSqlParser; import com.baomidou.mybatisplus.extension.plugins.tenant.TenantSqlParser;
import com.baomidou.mybatisplus.core.parser.ISqlParser; import com.baomidou.mybatisplus.core.parser.ISqlParser;
import org.apache.ibatis.mapping.MappedStatement;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
</#if> </#if>
...@@ -29,7 +33,11 @@ import java.util.List; ...@@ -29,7 +33,11 @@ import java.util.List;
@Configuration @Configuration
@MapperScan(value="${pub.getPKGCodeName()}.core.*.mapper",nameGenerator = UniqueNameGenerator.class) @MapperScan(value="${pub.getPKGCodeName()}.core.*.mapper",nameGenerator = UniqueNameGenerator.class)
public class MybatisConfiguration { public class MybatisConfiguration {
<#if sys.getSaaSMode()==2>
@Autowired
private SaaSTenantProperties saaSTenantProperties;
</#if>
/** /**
* mybatis适配多数据库 * mybatis适配多数据库
* @return * @return
...@@ -68,12 +76,27 @@ public class MybatisConfiguration { ...@@ -68,12 +76,27 @@ public class MybatisConfiguration {
tenantSqlParser.setTenantHandler(saaSTenantHandler); tenantSqlParser.setTenantHandler(saaSTenantHandler);
sqlParserList.add(tenantSqlParser); sqlParserList.add(tenantSqlParser);
paginationInterceptor.setSqlParserList(sqlParserList); paginationInterceptor.setSqlParserList(sqlParserList);
// 设置租户忽略
paginationInterceptor.setSqlParserFilter(ignoreParserFilter());
</#if> </#if>
// 开启 count join 优化,只针对部分 left join // 开启 count join 优化,只针对部分 left join
paginationInterceptor.setCountSqlParser(new JsqlParserCountOptimize(true)); paginationInterceptor.setCountSqlParser(new JsqlParserCountOptimize(true));
return paginationInterceptor; return paginationInterceptor;
} }
@Bean
public ISqlParserFilter ignoreParserFilter() {
return metaObject -> {
// 此处就过滤
MappedStatement ms = SqlParserHelper.getMappedStatement(metaObject);
if (saaSTenantProperties.getIgnoreMappers().contains(ms.getId())) {
return true;
}
return false;
};
}
<#--/**--> <#--/**-->
<#--* mybatis-plus逻辑有效--> <#--* mybatis-plus逻辑有效-->
......
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册