From 0aac6920c41eccbc78842cdb5aaa35b43472c61f Mon Sep 17 00:00:00 2001 From: CoolMoon <@%Ccl8314&> Date: Wed, 6 May 2020 11:57:57 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E5=A2=9E=E5=8A=A0swagger=E4=BE=9D=E8=B5=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../bridge/MybatisGeneratorBridge.java | 2 + .../plugins/DbRemarksCommentGenerator.java | 85 +++++++++++-------- 2 files changed, 53 insertions(+), 34 deletions(-) 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 29714494..d8f2558c 100644 --- a/src/main/java/com/zzg/mybatis/generator/bridge/MybatisGeneratorBridge.java +++ b/src/main/java/com/zzg/mybatis/generator/bridge/MybatisGeneratorBridge.java @@ -196,6 +196,8 @@ public void generate() throws Exception { pluginConfiguration.setConfigurationType("com.softwareloop.mybatis.generator.plugins.LombokPlugin"); context.addPluginConfiguration(pluginConfiguration); } + + // toString, hashCode, equals插件 else if (generatorConfig.isNeedToStringHashcodeEquals()) { PluginConfiguration pluginConfiguration1 = new PluginConfiguration(); 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 ecc17b5f..5238867b 100644 --- a/src/main/java/com/zzg/mybatis/generator/plugins/DbRemarksCommentGenerator.java +++ b/src/main/java/com/zzg/mybatis/generator/plugins/DbRemarksCommentGenerator.java @@ -21,8 +21,9 @@ import org.mybatis.generator.api.IntrospectedTable; import org.mybatis.generator.api.dom.java.*; import org.mybatis.generator.api.dom.xml.XmlElement; -import org.mybatis.generator.internal.util.StringUtility; +import java.text.SimpleDateFormat; +import java.util.Calendar; import java.util.Properties; import java.util.Set; @@ -40,6 +41,7 @@ public class DbRemarksCommentGenerator implements CommentGenerator { private Properties properties; private boolean columnRemarks; private boolean isAnnotations; + private SimpleDateFormat dateFormat=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); public DbRemarksCommentGenerator() { super(); @@ -47,24 +49,25 @@ public DbRemarksCommentGenerator() { } + @Override public void addJavaFileComment(CompilationUnit compilationUnit) { // add no file level comments by default if (isAnnotations) { - compilationUnit.addImportedType(new FullyQualifiedJavaType("javax.persistence.Table")); - compilationUnit.addImportedType(new FullyQualifiedJavaType("javax.persistence.Id")); - compilationUnit.addImportedType(new FullyQualifiedJavaType("javax.persistence.Column")); - compilationUnit.addImportedType(new FullyQualifiedJavaType("javax.persistence.GeneratedValue")); + compilationUnit.addImportedType(new FullyQualifiedJavaType("javax.persistence.*")); compilationUnit.addImportedType(new FullyQualifiedJavaType("org.hibernate.validator.constraints.NotEmpty")); } + compilationUnit.addImportedType(new FullyQualifiedJavaType("io.swagger.annotations.ApiModelProperty")); } /** * Adds a suitable comment to warn users that the element was generated, and * when it was generated. */ + @Override public void addComment(XmlElement xmlElement) { } + @Override public void addRootComment(XmlElement rootElement) { // add no document level comments by default return; @@ -96,7 +99,8 @@ public void addClassAnnotation(InnerClass innerClass, IntrospectedTable introspe } - public void addConfigurationProperties(Properties properties) { + @Override + public void addConfigurationProperties(Properties properties) { this.properties.putAll(properties); columnRemarks = isTrue(properties .getProperty("columnRemarks")); @@ -104,47 +108,55 @@ public void addConfigurationProperties(Properties properties) { .getProperty("annotations")); } + @Override public void addClassComment(InnerClass innerClass, - IntrospectedTable introspectedTable) { + IntrospectedTable introspectedTable) { } + @Override public void addModelClassComment(TopLevelClass topLevelClass, - IntrospectedTable introspectedTable) { + IntrospectedTable introspectedTable) { + topLevelClass.addJavaDocLine("/**"); topLevelClass.addJavaDocLine(" * " + introspectedTable.getFullyQualifiedTable().getIntrospectedTableName()); - topLevelClass.addJavaDocLine(" * @author "); + topLevelClass.addJavaDocLine(" * @Description : "); + topLevelClass.addJavaDocLine(" * @Author : ChenChunlei "); + topLevelClass.addJavaDocLine(" * @Date : "+dateFormat.format(Calendar.getInstance().getTime())); topLevelClass.addJavaDocLine(" */"); if(isAnnotations) { topLevelClass.addAnnotation("@Table(name=\"" + introspectedTable.getFullyQualifiedTableNameAtRuntime() + "\")"); } } + @Override public void addEnumComment(InnerEnum innerEnum, - IntrospectedTable introspectedTable) { + IntrospectedTable introspectedTable) { } + @Override public void addFieldComment(Field field, - IntrospectedTable introspectedTable, - IntrospectedColumn introspectedColumn) { - if (StringUtility.stringHasValue(introspectedColumn.getRemarks())) { - field.addJavaDocLine("/**"); - StringBuilder sb = new StringBuilder(); - sb.append(" * "); - sb.append(introspectedColumn.getRemarks()); - field.addJavaDocLine(sb.toString()); - field.addJavaDocLine(" */"); - } + IntrospectedTable introspectedTable, + IntrospectedColumn introspectedColumn) { +// if (StringUtility.stringHasValue(introspectedColumn.getRemarks())) { +// field.addJavaDocLine("/**"); +// StringBuilder sb = new StringBuilder(); +// sb.append(" * "); +// sb.append(introspectedColumn.getRemarks()); +// field.addJavaDocLine(sb.toString()); +// field.addJavaDocLine(" */"); +// } + field.addJavaDocLine("@ApiModelProperty(value=\""+introspectedColumn.getRemarks()+"\")"); if (isAnnotations) { boolean isId = false; - for (IntrospectedColumn column : introspectedTable.getPrimaryKeyColumns()) { - if (introspectedColumn == column) { - isId = true; - field.addAnnotation("@Id"); - field.addAnnotation("@GeneratedValue"); - break; - } - } +// for (IntrospectedColumn column : introspectedTable.getPrimaryKeyColumns()) { +// if (introspectedColumn == column) { +//// isId = true; +// field.addAnnotation("@Id"); +//// field.addAnnotation("@GeneratedValue"); +// break; +// } +// } if (!introspectedColumn.isNullable() && !isId){ field.addAnnotation("@NotEmpty"); } @@ -160,25 +172,30 @@ public void addFieldComment(Field field, } } + @Override public void addFieldComment(Field field, IntrospectedTable introspectedTable) { } + @Override public void addGeneralMethodComment(Method method, - IntrospectedTable introspectedTable) { + IntrospectedTable introspectedTable) { } + @Override public void addGetterComment(Method method, - IntrospectedTable introspectedTable, - IntrospectedColumn introspectedColumn) { + IntrospectedTable introspectedTable, + IntrospectedColumn introspectedColumn) { } + @Override public void addSetterComment(Method method, - IntrospectedTable introspectedTable, - IntrospectedColumn introspectedColumn) { + IntrospectedTable introspectedTable, + IntrospectedColumn introspectedColumn) { } + @Override public void addClassComment(InnerClass innerClass, - IntrospectedTable introspectedTable, boolean markAsDoNotDelete) { + IntrospectedTable introspectedTable, boolean markAsDoNotDelete) { innerClass.addJavaDocLine("/**"); //$NON-NLS-1$ innerClass.addJavaDocLine(" */"); //$NON-NLS-1$ } From 9309bfd04efca777ce59282566bd86417cd9eb3f Mon Sep 17 00:00:00 2001 From: CoolMoon <@%Ccl8314&> Date: Wed, 6 May 2020 12:44:28 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E5=A2=9E=E5=8A=A0swagger=E4=BE=9D=E8=B5=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../generator/plugins/DbRemarksCommentGenerator.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) 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 5238867b..aff6e56c 100644 --- a/src/main/java/com/zzg/mybatis/generator/plugins/DbRemarksCommentGenerator.java +++ b/src/main/java/com/zzg/mybatis/generator/plugins/DbRemarksCommentGenerator.java @@ -148,7 +148,7 @@ public void addFieldComment(Field field, field.addJavaDocLine("@ApiModelProperty(value=\""+introspectedColumn.getRemarks()+"\")"); if (isAnnotations) { - boolean isId = false; +// boolean isId = false; // for (IntrospectedColumn column : introspectedTable.getPrimaryKeyColumns()) { // if (introspectedColumn == column) { //// isId = true; @@ -157,9 +157,9 @@ public void addFieldComment(Field field, // break; // } // } - if (!introspectedColumn.isNullable() && !isId){ - field.addAnnotation("@NotEmpty"); - } +// if (!introspectedColumn.isNullable() && !isId){ +// field.addAnnotation("@NotEmpty"); +// } if (introspectedColumn.isIdentity()) { if (introspectedTable.getTableConfiguration().getGeneratedKey().getRuntimeSqlStatement().equals("JDBC")) { field.addAnnotation("@GeneratedValue(generator = \"JDBC\")");