From 8dfd971214513a7ea95795a559ae5983630f0b6a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=80=E6=BA=90=E6=B5=B7=E5=93=A5?= Date: Wed, 14 Jun 2023 09:41:35 +0800 Subject: [PATCH] =?UTF-8?q?fixed:=20=E4=BF=AE=E5=A4=8D=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E5=BA=93=E5=AD=97=E6=AE=B5=E5=B7=B2=E4=B8=8B=E5=88=92=E7=BA=BF?= =?UTF-8?q?=20=5F=20=E5=BC=80=E5=A4=B4=E6=88=96=E8=80=85=E7=BB=93=E5=B0=BE?= =?UTF-8?q?=E6=97=B6=EF=BC=8C=E7=94=9F=E6=88=90=E7=9A=84=20entity=20?= =?UTF-8?q?=E5=AD=97=E6=AE=B5=E9=85=8D=E7=BD=AE=E4=B8=8D=E6=AD=A3=E7=A1=AE?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mybatisflex/codegen/entity/Column.java | 19 +++++++++++++++---- .../mybatisflex/coretest/StringUtilTest.java | 17 +++++++++++++++++ 2 files changed, 32 insertions(+), 4 deletions(-) create mode 100644 mybatis-flex-core/src/test/java/com/mybatisflex/coretest/StringUtilTest.java diff --git a/mybatis-flex-codegen/src/main/java/com/mybatisflex/codegen/entity/Column.java b/mybatis-flex-codegen/src/main/java/com/mybatisflex/codegen/entity/Column.java index 6daef109..e936b4fb 100644 --- a/mybatis-flex-codegen/src/main/java/com/mybatisflex/codegen/entity/Column.java +++ b/mybatis-flex-codegen/src/main/java/com/mybatisflex/codegen/entity/Column.java @@ -35,6 +35,8 @@ public class Column { private boolean isPrimaryKey = false; private Boolean isAutoIncrement; + private boolean needGenColumnAnnotation = false; + private ColumnConfig columnConfig; @@ -45,6 +47,7 @@ public class Column { public void setName(String name) { this.name = name; this.property = buildPropertyName(); + this.needGenColumnAnnotation = !name.equalsIgnoreCase(StringUtil.camelToUnderline(property)); } public String getProperty() { @@ -104,10 +107,10 @@ public class Column { } - public String buildComment(){ - if (StringUtil.isBlank(comment)){ + public String buildComment() { + if (StringUtil.isBlank(comment)) { return ""; - }else { + } else { StringBuilder sb = new StringBuilder("/**\n") .append(" * ").append(comment).append("\n") .append(" */"); @@ -164,10 +167,17 @@ public class Column { || columnConfig.getJdbcType() != null || columnConfig.getTypeHandler() != null || columnConfig.getTenantId() != null + || needGenColumnAnnotation ) { annotations.append("@Column("); boolean needComma = false; + if (needGenColumnAnnotation) { + annotations.append("value = \"" + name + "\""); + needComma = true; + } + if (columnConfig.getOnInsertValue() != null) { + addComma(annotations, needComma); annotations.append("onInsertValue = \"" + columnConfig.getOnInsertValue() + "\""); needComma = true; } @@ -265,7 +275,8 @@ public class Column { || columnConfig.getVersion() != null || columnConfig.getJdbcType() != null || columnConfig.getTypeHandler() != null - || Boolean.TRUE.equals(columnConfig.getTenantId()) + || Boolean.TRUE.equals(columnConfig.getTenantId() + || needGenColumnAnnotation) ) { importClasses.add(com.mybatisflex.annotation.Column.class.getName()); } diff --git a/mybatis-flex-core/src/test/java/com/mybatisflex/coretest/StringUtilTest.java b/mybatis-flex-core/src/test/java/com/mybatisflex/coretest/StringUtilTest.java new file mode 100644 index 00000000..03211599 --- /dev/null +++ b/mybatis-flex-core/src/test/java/com/mybatisflex/coretest/StringUtilTest.java @@ -0,0 +1,17 @@ +package com.mybatisflex.coretest; + +import com.mybatisflex.core.util.StringUtil; +import org.junit.Test; + +public class StringUtilTest { + + @Test + public void underlineToCamel() { + String testString1 = "aa_bb_"; + String underlineToCamel = StringUtil.underlineToCamel(testString1); + System.out.println(underlineToCamel); + + String underline = StringUtil.camelToUnderline(underlineToCamel); + System.out.println(underline); + } +}