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); + } +}