mirror of
https://gitee.com/mybatis-flex/mybatis-flex.git
synced 2025-12-07 17:18:24 +08:00
fixed: 修复数据库字段已下划线 _ 开头或者结尾时,生成的 entity 字段配置不正确的问题
This commit is contained in:
parent
d8fa3b19bd
commit
8dfd971214
@ -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());
|
||||
}
|
||||
|
||||
@ -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);
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user