🐛 Fixing a bug. #I25JZN 代码生成中的预览、下载出错

This commit is contained in:
jovlog 2020-11-16 17:24:59 +08:00
parent 8ee3bc5a39
commit 878aac7abc
2 changed files with 8 additions and 4 deletions

View File

@ -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;
}
/**

View File

@ -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<GenFormConf> formConfList = genFormConfMapper.selectList(Wrappers.<GenFormConf>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();
}