From 6b641cc1b927bfcd4b0dd88bc4f1c9c48ddbae98 Mon Sep 17 00:00:00 2001 From: caozhen <18736171426@139.com> Date: Thu, 16 Mar 2023 16:00:06 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B2=A1=E5=AF=BC=E5=85=A5=E8=A1=A8=E5=A4=87?= =?UTF-8?q?=E6=B3=A8bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../database/DbReadTableUtil.java | 50 ++++++++++++++++++- .../impl/OnlCgformHeadServiceImpl.java | 10 +++- 2 files changed, 58 insertions(+), 2 deletions(-) diff --git a/jero-boot/jero-boot-base/jero-boot-base-generater-core/src/main/java/com/jero/codegenerate/database/DbReadTableUtil.java b/jero-boot/jero-boot-base/jero-boot-base-generater-core/src/main/java/com/jero/codegenerate/database/DbReadTableUtil.java index 4f079a4a..c144097e 100644 --- a/jero-boot/jero-boot-base/jero-boot-base-generater-core/src/main/java/com/jero/codegenerate/database/DbReadTableUtil.java +++ b/jero-boot/jero-boot-base/jero-boot-base-generater-core/src/main/java/com/jero/codegenerate/database/DbReadTableUtil.java @@ -19,8 +19,10 @@ import org.apache.commons.lang.StringUtils; import com.jero.codegenerate.database.util.CodeStringUtils; import com.jero.codegenerate.generate.pojo.ColumnVo; import com.jero.codegenerate.generate.util.TableConvert; +import org.springframework.stereotype.Component; @Slf4j +@Component public class DbReadTableUtil { private static Connection connection; @@ -32,7 +34,6 @@ public class DbReadTableUtil { private static final String CONNECT_DATABASE_NAME = " connect databaseName : "; private static final String COLUMN_GET_FIELD_NAME = "columnt.getFieldName() -------------"; - public static void main(String[] args) throws SQLException { try { List list = listColumns("demo"); @@ -526,4 +527,51 @@ public class DbReadTableUtil { return value; } + + //获取当前使用数据库名 + public String database() throws Exception { + Class.forName(com.jero.codegenerate.properties.CodeConfigProperties.driverName); + connection = DriverManager.getConnection(com.jero.codegenerate.properties.CodeConfigProperties.databaseUrl, com.jero.codegenerate.properties.CodeConfigProperties.username, com.jero.codegenerate.properties.CodeConfigProperties.password); + statement = connection.createStatement(1005, 1007); + String sqlStr = "select database()"; + ResultSet resultSet = statement.executeQuery(sqlStr); + while(resultSet.next()) { + String name = resultSet.getString(1); + this.release(connection,statement); + return name; + } + this.release(connection,statement); + return ""; + } + + //通过表名获取表备注 + public String remarks(String a) throws Exception { + String database = this.database(); + + Class.forName(com.jero.codegenerate.properties.CodeConfigProperties.driverName); + connection = DriverManager.getConnection(com.jero.codegenerate.properties.CodeConfigProperties.databaseUrl, com.jero.codegenerate.properties.CodeConfigProperties.username, com.jero.codegenerate.properties.CodeConfigProperties.password); + statement = connection.createStatement(1005, 1007); + + String sqlStr = "SELECT table_comment FROM information_schema.TABLES WHERE table_schema = " + "'"+database+"'" + " AND table_name = " + "'"+a+"'"; + ResultSet resultSet = statement.executeQuery(sqlStr); + while(resultSet.next()) { + String name = resultSet.getString(1); + this.release(connection,statement); + return name; + } + this.release(connection,statement); + return ""; + } + + //释放连接资源 + public void release(Connection connection, Statement statement) throws Exception { + if (statement != null) { + statement.close(); + statement = null; + } + if (connection != null) { + connection.close(); + connection = null; + } + } } diff --git a/jero-boot/jero-boot-base/jero-boot-base-generater/src/main/java/com/jero/generater/modules/online/cgform/service/impl/OnlCgformHeadServiceImpl.java b/jero-boot/jero-boot-base/jero-boot-base-generater/src/main/java/com/jero/generater/modules/online/cgform/service/impl/OnlCgformHeadServiceImpl.java index 652b2294..f83e3974 100644 --- a/jero-boot/jero-boot-base/jero-boot-base-generater/src/main/java/com/jero/generater/modules/online/cgform/service/impl/OnlCgformHeadServiceImpl.java +++ b/jero-boot/jero-boot-base/jero-boot-base-generater/src/main/java/com/jero/generater/modules/online/cgform/service/impl/OnlCgformHeadServiceImpl.java @@ -89,6 +89,8 @@ public class OnlCgformHeadServiceImpl extends ServiceImpl