diff --git a/README.md b/README.md index 9b83421..b623ff1 100644 --- a/README.md +++ b/README.md @@ -32,6 +32,8 @@ public class GeberatorUIServer { .userName("root") .password("root") .driverClassName("com.mysql.cj.jdbc.Driver") + //数据库schema,POSTGRE_SQL,ORACLE,DB2类型的数据库需要指定 + .schemaName("myBusiness") .basePackage("com.github.davidfantasy.mybatisplustools.example") .port(8068) .build(); diff --git a/pom.xml b/pom.xml index 2bd2b10..6d271bd 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ com.github.davidfantasy mybatis-plus-generator-ui - 1.1.0 + 1.1.1 4.0.0 mybatis-plus-generator-ui diff --git a/src/main/java/com/github/davidfantasy/mybatisplus/generatorui/ApplicationConfigure.java b/src/main/java/com/github/davidfantasy/mybatisplus/generatorui/ApplicationConfigure.java index 4687493..919edb6 100644 --- a/src/main/java/com/github/davidfantasy/mybatisplus/generatorui/ApplicationConfigure.java +++ b/src/main/java/com/github/davidfantasy/mybatisplus/generatorui/ApplicationConfigure.java @@ -39,6 +39,7 @@ public DataSourceConfig dataSourceConfig(GeneratorConfig config) { dataSourceConfig.setDriverName(config.getDriverClassName()); dataSourceConfig.setUsername(config.getUserName()); dataSourceConfig.setPassword(config.getPassword()); + dataSourceConfig.setSchemaName(config.getSchemaName()); return dataSourceConfig; } diff --git a/src/main/java/com/github/davidfantasy/mybatisplus/generatorui/GeneratorConfig.java b/src/main/java/com/github/davidfantasy/mybatisplus/generatorui/GeneratorConfig.java index 2530369..85fe570 100644 --- a/src/main/java/com/github/davidfantasy/mybatisplus/generatorui/GeneratorConfig.java +++ b/src/main/java/com/github/davidfantasy/mybatisplus/generatorui/GeneratorConfig.java @@ -26,6 +26,11 @@ public class GeneratorConfig { */ private String jdbcUrl; + /** + * 数据库schema,POSTGRE_SQL,ORACLE,DB2类型的数据库需要指定 + */ + private String schemaName; + /** * 数据库用户名 */ diff --git a/src/main/java/com/github/davidfantasy/mybatisplus/generatorui/service/DatabaseService.java b/src/main/java/com/github/davidfantasy/mybatisplus/generatorui/service/DatabaseService.java index 6cdfdda..a1a2739 100644 --- a/src/main/java/com/github/davidfantasy/mybatisplus/generatorui/service/DatabaseService.java +++ b/src/main/java/com/github/davidfantasy/mybatisplus/generatorui/service/DatabaseService.java @@ -1,9 +1,11 @@ package com.github.davidfantasy.mybatisplus.generatorui.service; +import com.baomidou.mybatisplus.annotation.DbType; import com.baomidou.mybatisplus.generator.config.DataSourceConfig; import com.baomidou.mybatisplus.generator.config.IDbQuery; import com.github.davidfantasy.mybatisplus.generatorui.dto.TableInfo; import com.google.common.collect.Lists; +import lombok.Data; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.stereotype.Service; @@ -23,7 +25,7 @@ public class DatabaseService { public List getTablesFromDb() { IDbQuery dbQuery = dataSourceConfig.getDbQuery(); - List> results = jdbcTemplate.queryForList(dbQuery.tablesSql()); + List> results = jdbcTemplate.queryForList(getTableSql()); List tableInfos = Lists.newArrayList(); for (Map table : results) { TableInfo tableInfo = new TableInfo(); @@ -34,4 +36,44 @@ public List getTablesFromDb() { return tableInfos; } + public String getTableSql() { + String tablesSql = dataSourceConfig.getDbQuery().tablesSql(); + if (DbType.POSTGRE_SQL == dataSourceConfig.getDbType()) { + String schema = dataSourceConfig.getSchemaName(); + if (schema == null) { + //pg 默认 schema=public + schema = "public"; + dataSourceConfig.setSchemaName(schema); + } + tablesSql = String.format(tablesSql, schema); + } else if (DbType.KINGBASE_ES == dataSourceConfig.getDbType()) { + String schema = dataSourceConfig.getSchemaName(); + if (schema == null) { + //kingbase 默认 schema=PUBLIC + schema = "PUBLIC"; + dataSourceConfig.setSchemaName(schema); + } + tablesSql = String.format(tablesSql, schema); + } else if (DbType.DB2 == dataSourceConfig.getDbType()) { + String schema = dataSourceConfig.getSchemaName(); + if (schema == null) { + //db2 默认 schema=current schema + schema = "current schema"; + dataSourceConfig.setSchemaName(schema); + } + tablesSql = String.format(tablesSql, schema); + } + //oracle数据库表太多,出现最大游标错误 + else if (DbType.ORACLE == dataSourceConfig.getDbType()) { + String schema = dataSourceConfig.getSchemaName(); + //oracle 默认 schema=username + if (schema == null) { + schema = dataSourceConfig.getUsername().toUpperCase(); + dataSourceConfig.setSchemaName(schema); + } + tablesSql = String.format(tablesSql, schema); + } + return tablesSql; + } + }