diff --git a/src/main/java/cn/iocoder/dashboard/modules/tool/dal/mysql/codegen/ToolSchemaColumnMapper.java b/src/main/java/cn/iocoder/dashboard/modules/tool/dal/mysql/codegen/ToolSchemaColumnMapper.java index 438168bc4..14a0302da 100644 --- a/src/main/java/cn/iocoder/dashboard/modules/tool/dal/mysql/codegen/ToolSchemaColumnMapper.java +++ b/src/main/java/cn/iocoder/dashboard/modules/tool/dal/mysql/codegen/ToolSchemaColumnMapper.java @@ -10,9 +10,10 @@ import java.util.List; @Mapper public interface ToolSchemaColumnMapper extends BaseMapperX { - default List selectListByTableName(String tableName) { + default List selectListByTableName(String tableSchema, String tableName) { return selectList(new QueryWrapper().eq("table_name", tableName) - .orderByAsc("ordinal_position")); + .eq("table_schema", tableSchema) + .orderByAsc("ordinal_position")); } } diff --git a/src/main/java/cn/iocoder/dashboard/modules/tool/dal/mysql/codegen/ToolSchemaTableMapper.java b/src/main/java/cn/iocoder/dashboard/modules/tool/dal/mysql/codegen/ToolSchemaTableMapper.java index 20a775272..622257c1c 100644 --- a/src/main/java/cn/iocoder/dashboard/modules/tool/dal/mysql/codegen/ToolSchemaTableMapper.java +++ b/src/main/java/cn/iocoder/dashboard/modules/tool/dal/mysql/codegen/ToolSchemaTableMapper.java @@ -22,8 +22,9 @@ public interface ToolSchemaTableMapper extends BaseMapperX { return selectList(new QueryWrapper().eq("table_schema", tableSchema)); } - default ToolSchemaTableDO selectByTableName(String tableName) { - return selectOne(new QueryWrapper().eq("table_name", tableName)); + default ToolSchemaTableDO selectByTableName1(String tableSchema, String tableName) { + return selectOne(new QueryWrapper().eq("table_schema",tableSchema) + .eq("table_name", tableName)); } } diff --git a/src/main/java/cn/iocoder/dashboard/modules/tool/service/codegen/impl/ToolCodegenServiceImpl.java b/src/main/java/cn/iocoder/dashboard/modules/tool/service/codegen/impl/ToolCodegenServiceImpl.java index 5b746f6fd..adb9fbfec 100644 --- a/src/main/java/cn/iocoder/dashboard/modules/tool/service/codegen/impl/ToolCodegenServiceImpl.java +++ b/src/main/java/cn/iocoder/dashboard/modules/tool/service/codegen/impl/ToolCodegenServiceImpl.java @@ -101,9 +101,11 @@ public class ToolCodegenServiceImpl implements ToolCodegenService { @Override public Long createCodegen(String tableName) { + //获取当前schema + String tableSchema = codegenProperties.getDbSchemas().iterator().next(); // 从数据库中,获得数据库表结构 - ToolSchemaTableDO schemaTable = schemaTableMapper.selectByTableName(tableName); - List schemaColumns = schemaColumnMapper.selectListByTableName(tableName); + ToolSchemaTableDO schemaTable = schemaTableMapper.selectByTableName1(tableSchema, tableName); + List schemaColumns = schemaColumnMapper.selectListByTableName(tableSchema, tableName); // 导入 return this.createCodegen0(ToolCodegenImportTypeEnum.DB, schemaTable, schemaColumns); } @@ -141,8 +143,9 @@ public class ToolCodegenServiceImpl implements ToolCodegenService { if (table == null) { throw exception(CODEGEN_TABLE_NOT_EXISTS); } + String tableSchema = codegenProperties.getDbSchemas().iterator().next(); // 从数据库中,获得数据库表结构 - List schemaColumns = schemaColumnMapper.selectListByTableName(table.getTableName()); + List schemaColumns = schemaColumnMapper.selectListByTableName(tableSchema, table.getTableName()); // 执行同步 this.syncCodegen0(tableId, schemaColumns);