diff --git a/pig-common/pig-common-datasource/src/main/java/com/pig4cloud/pig/common/datasource/config/LastParamDsProcessor.java b/pig-common/pig-common-datasource/src/main/java/com/pig4cloud/pig/common/datasource/config/LastParamDsProcessor.java index e7ea493e..87e13f3c 100644 --- a/pig-common/pig-common-datasource/src/main/java/com/pig4cloud/pig/common/datasource/config/LastParamDsProcessor.java +++ b/pig-common/pig-common-datasource/src/main/java/com/pig4cloud/pig/common/datasource/config/LastParamDsProcessor.java @@ -17,6 +17,7 @@ package com.pig4cloud.pig.common.datasource.config; import com.baomidou.dynamic.datasource.processor.DsProcessor; +import com.baomidou.dynamic.datasource.toolkit.DynamicDataSourceContextHolder; import org.aopalliance.intercept.MethodInvocation; /** @@ -36,7 +37,12 @@ public class LastParamDsProcessor extends DsProcessor { */ @Override public boolean matches(String key) { - return key.startsWith(LAST_PREFIX); + if (key.startsWith(LAST_PREFIX)) { + // https://github.com/baomidou/dynamic-datasource-spring-boot-starter/issues/213 + DynamicDataSourceContextHolder.clear(); + return true; + } + return false; } /** diff --git a/pig-visual/pig-codegen/src/main/java/com/pig4cloud/pig/codegen/service/impl/GeneratorServiceImpl.java b/pig-visual/pig-codegen/src/main/java/com/pig4cloud/pig/codegen/service/impl/GeneratorServiceImpl.java index 71864c57..570ea10e 100755 --- a/pig-visual/pig-codegen/src/main/java/com/pig4cloud/pig/codegen/service/impl/GeneratorServiceImpl.java +++ b/pig-visual/pig-codegen/src/main/java/com/pig4cloud/pig/codegen/service/impl/GeneratorServiceImpl.java @@ -21,7 +21,6 @@ import cn.hutool.core.io.IoUtil; import cn.hutool.core.map.MapUtil; import cn.hutool.core.util.StrUtil; import com.baomidou.dynamic.datasource.annotation.DS; -import com.baomidou.dynamic.datasource.toolkit.DynamicDataSourceContextHolder; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; @@ -76,8 +75,6 @@ public class GeneratorServiceImpl implements GeneratorService { List formConfList = genFormConfMapper.selectList(Wrappers.lambdaQuery() .eq(GenFormConf::getTableName, genConfig.getTableName()).orderByDesc(GenFormConf::getCreateTime)); - DynamicDataSourceContextHolder.push(genConfig.getDsName()); - String tableNames = genConfig.getTableName(); for (String tableName : StrUtil.split(tableNames, StrUtil.DASHED)) { // 查询表信息 @@ -92,6 +89,7 @@ public class GeneratorServiceImpl implements GeneratorService { return CodeGenUtils.generatorCode(genConfig, table, columns, null, null); } } + return MapUtil.empty(); }