From 6ebbbcb2ae111c8d07482959901eea8fac4d7a82 Mon Sep 17 00:00:00 2001 From: zouzhigang Date: Thu, 22 Mar 2018 14:00:42 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8D=87=E7=BA=A7mybatis-generator-core?= =?UTF-8?q?=E7=89=88=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 2 +- .../bridge/MybatisGeneratorBridge.java | 10 ++++++- .../plugins/DbRemarksCommentGenerator.java | 30 ++++++++++++++++++- 3 files changed, 39 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index 7ecdb5df..4b2e8aa0 100644 --- a/pom.xml +++ b/pom.xml @@ -15,7 +15,7 @@ org.mybatis.generator mybatis-generator-core - 1.3.5 + 1.3.6 ch.qos.logback diff --git a/src/main/java/com/zzg/mybatis/generator/bridge/MybatisGeneratorBridge.java b/src/main/java/com/zzg/mybatis/generator/bridge/MybatisGeneratorBridge.java index 13a9c213..ceaafee0 100644 --- a/src/main/java/com/zzg/mybatis/generator/bridge/MybatisGeneratorBridge.java +++ b/src/main/java/com/zzg/mybatis/generator/bridge/MybatisGeneratorBridge.java @@ -70,7 +70,11 @@ public void generate() throws Exception { tableConfig.setSelectByExampleStatementEnabled(false); } - tableConfig.setSchema(selectedDatabaseConfig.getSchema()); + if (DbType.MySQL.name().equals(selectedDatabaseConfig.getDbType())) { + tableConfig.setSchema(selectedDatabaseConfig.getSchema()); + } else { + tableConfig.setCatalog(selectedDatabaseConfig.getSchema()); + } // 针对 postgresql 单独配置 if (DbType.valueOf(selectedDatabaseConfig.getDbType()).getDriverClass() == "org.postgresql.Driver") { @@ -100,6 +104,10 @@ public void generate() throws Exception { tableConfig.addProperty("useActualColumnNames", "true"); } JDBCConnectionConfiguration jdbcConfig = new JDBCConnectionConfiguration(); + // http://www.mybatis.org/generator/usage/mysql.html + if (DbType.MySQL.name().equals(selectedDatabaseConfig.getDbType())) { + jdbcConfig.addProperty("nullCatalogMeansCurrent", "true"); + } jdbcConfig.setDriverClass(DbType.valueOf(selectedDatabaseConfig.getDbType()).getDriverClass()); jdbcConfig.setConnectionURL(DbUtil.getConnectionUrlWithSchema(selectedDatabaseConfig)); jdbcConfig.setUserId(selectedDatabaseConfig.getUsername()); diff --git a/src/main/java/com/zzg/mybatis/generator/plugins/DbRemarksCommentGenerator.java b/src/main/java/com/zzg/mybatis/generator/plugins/DbRemarksCommentGenerator.java index e6c9791d..ecc17b5f 100644 --- a/src/main/java/com/zzg/mybatis/generator/plugins/DbRemarksCommentGenerator.java +++ b/src/main/java/com/zzg/mybatis/generator/plugins/DbRemarksCommentGenerator.java @@ -24,6 +24,7 @@ import org.mybatis.generator.internal.util.StringUtility; import java.util.Properties; +import java.util.Set; import static org.mybatis.generator.internal.util.StringUtility.isTrue; @@ -69,7 +70,33 @@ public void addRootComment(XmlElement rootElement) { return; } - public void addConfigurationProperties(Properties properties) { + @Override + public void addGeneralMethodAnnotation(Method method, IntrospectedTable introspectedTable, Set set) { + + + } + + @Override + public void addGeneralMethodAnnotation(Method method, IntrospectedTable introspectedTable, IntrospectedColumn introspectedColumn, Set set) { + + } + + @Override + public void addFieldAnnotation(Field field, IntrospectedTable introspectedTable, Set set) { + + } + + @Override + public void addFieldAnnotation(Field field, IntrospectedTable introspectedTable, IntrospectedColumn introspectedColumn, Set set) { + + } + + @Override + public void addClassAnnotation(InnerClass innerClass, IntrospectedTable introspectedTable, Set set) { + + } + + public void addConfigurationProperties(Properties properties) { this.properties.putAll(properties); columnRemarks = isTrue(properties .getProperty("columnRemarks")); @@ -84,6 +111,7 @@ public void addClassComment(InnerClass innerClass, public void addModelClassComment(TopLevelClass topLevelClass, IntrospectedTable introspectedTable) { topLevelClass.addJavaDocLine("/**"); + topLevelClass.addJavaDocLine(" * " + introspectedTable.getFullyQualifiedTable().getIntrospectedTableName()); topLevelClass.addJavaDocLine(" * @author "); topLevelClass.addJavaDocLine(" */"); if(isAnnotations) {