!87 fix:用户不设置全表 schema 时,使用 TableConfig 配置 schema 不生效。

Merge pull request !87 from 王帅/main
This commit is contained in:
Michael Yang 2023-06-22 05:51:40 +00:00 committed by Gitee
commit b4170c92f0
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
4 changed files with 36 additions and 25 deletions

View File

@ -16,7 +16,6 @@
package com.mybatisflex.codegen.config;
import com.mybatisflex.codegen.template.ITemplate;
import com.mybatisflex.core.util.StringUtil;
import java.util.HashMap;
import java.util.Map;
@ -501,7 +500,7 @@ public class GlobalConfig {
}
/**
* @see StrategyConfig#setTablePrefix(String)
* @see StrategyConfig#setTablePrefix(String...)
*/
public void setTablePrefix(String... tablePrefix) {
getStrategyConfig().setTablePrefix(tablePrefix);

View File

@ -32,7 +32,7 @@ public class TableDefConfig {
/**
* TableDef 类的后缀
*/
private String classSuffix = "Def";
private String classSuffix = "TableDef";
/**
* 是否覆盖之前生成的文件

View File

@ -57,7 +57,7 @@ public class Column {
/**
* 是否自增
*/
private Boolean isAutoIncrement;
private boolean isAutoIncrement;
/**
* 是否需要生成 @Column 注解
@ -139,10 +139,9 @@ public class Column {
if (StringUtil.isBlank(comment)) {
return "";
} else {
StringBuilder sb = new StringBuilder("/**\n")
.append(" * ").append(comment).append("\n")
.append(" */");
return sb.toString();
return "/**\n" +
" * " + comment + "\n" +
" */";
}
}
@ -163,19 +162,19 @@ public class Column {
annotations.append("keyType = KeyType.Auto");
needComma = true;
} else if (columnConfig.getKeyType() != null) {
annotations.append("keyType = KeyType." + columnConfig.getKeyType().name());
annotations.append("keyType = KeyType.").append(columnConfig.getKeyType().name());
needComma = true;
}
if (columnConfig.getKeyValue() != null) {
addComma(annotations, needComma);
annotations.append("value = \"" + columnConfig.getKeyValue() + "\"");
annotations.append("value = \"").append(columnConfig.getKeyValue()).append("\"");
needComma = true;
}
if (columnConfig.getKeyBefore() != null) {
addComma(annotations, needComma);
annotations.append("before = " + columnConfig.getKeyBefore());
annotations.append("before = ").append(columnConfig.getKeyBefore());
}
if (annotations.length() == 4) {
@ -199,43 +198,43 @@ public class Column {
annotations.append("@Column(");
boolean needComma = false;
if (needGenColumnAnnotation) {
annotations.append("value = \"" + name + "\"");
annotations.append("value = \"").append(name).append("\"");
needComma = true;
}
if (columnConfig.getOnInsertValue() != null) {
addComma(annotations, needComma);
annotations.append("onInsertValue = \"" + columnConfig.getOnInsertValue() + "\"");
annotations.append("onInsertValue = \"").append(columnConfig.getOnInsertValue()).append("\"");
needComma = true;
}
if (columnConfig.getOnUpdateValue() != null) {
addComma(annotations, needComma);
annotations.append("onUpdateValue = \"" + columnConfig.getOnUpdateValue() + "\"");
annotations.append("onUpdateValue = \"").append(columnConfig.getOnUpdateValue()).append("\"");
needComma = true;
}
if (columnConfig.getLarge() != null) {
addComma(annotations, needComma);
annotations.append("isLarge = " + columnConfig.getLarge());
annotations.append("isLarge = ").append(columnConfig.getLarge());
needComma = true;
}
if (columnConfig.getLogicDelete() != null) {
addComma(annotations, needComma);
annotations.append("isLogicDelete = " + columnConfig.getLogicDelete());
annotations.append("isLogicDelete = ").append(columnConfig.getLogicDelete());
needComma = true;
}
if (columnConfig.getVersion() != null) {
addComma(annotations, needComma);
annotations.append("version = " + columnConfig.getVersion());
annotations.append("version = ").append(columnConfig.getVersion());
needComma = true;
}
if (columnConfig.getJdbcType() != null) {
addComma(annotations, needComma);
annotations.append("jdbcType = JdbcType." + columnConfig.getJdbcType().name());
annotations.append("jdbcType = JdbcType.").append(columnConfig.getJdbcType().name());
needComma = true;
}
if (columnConfig.getTypeHandler() != null) {
addComma(annotations, needComma);
annotations.append("typeHandler = " + columnConfig.getTypeHandler().getSimpleName() + ".class");
annotations.append("typeHandler = ").append(columnConfig.getTypeHandler().getSimpleName()).append(".class");
needComma = true;
}
if (Boolean.TRUE.equals(columnConfig.getTenantId())) {
@ -247,7 +246,7 @@ public class Column {
//@ColumnMask 注解
if (columnConfig.getMask() != null) {
annotations.append("@ColumnMask(\"" + columnConfig.getMask() + "\")");
annotations.append("@ColumnMask(\"").append(columnConfig.getMask()).append("\")");
}
String result = annotations.toString();

View File

@ -203,14 +203,27 @@ public class Table {
tableAnnotation.append("@Table(value = \"").append(name).append("\"");
if (StringUtil.isNotBlank(schema)) {
tableAnnotation.append(", schema = \"").append(schema).append("\"");
String globalSchema;
if (tableConfig == null) {
// 未配置 tableConfig 以策略中的 schema 为主
globalSchema = schema;
} else if (StringUtil.isBlank(tableConfig.getSchema())) {
// 配置 tableConfig 但未指定 schema 还是以策略中的 schema 为主
globalSchema = schema;
} else {
// 以用户设置的 tableConfig 中的 schema 为主
globalSchema = null;
}
if (StringUtil.isNotBlank(globalSchema)) {
tableAnnotation.append(", schema = \"").append(globalSchema).append("\"");
}
if (tableConfig != null) {
// if (tableConfig.getSchema() != null) {
// tableAnnotation.append(", schema = \"").append(tableConfig.getSchema()).append("\"");
// }
if (StringUtil.isNotBlank(tableConfig.getSchema())) {
tableAnnotation.append(", schema = \"").append(tableConfig.getSchema()).append("\"");
}
if (tableConfig.getCamelToUnderline() != null) {
tableAnnotation.append(", camelToUnderline = \"").append(tableConfig.getCamelToUnderline()).append("\"");
}