refactor: optimize TableInfo.setTableName

This commit is contained in:
开源海哥 2023-08-17 14:00:27 +08:00
parent 4af6863b82
commit b325882a35
4 changed files with 24 additions and 4 deletions

View File

@ -150,7 +150,17 @@ public class TableInfo {
} }
public void setTableName(String tableName) { public void setTableName(String tableName) {
this.tableName = tableName; int indexOf = tableName.indexOf(".");
if (indexOf > 0) {
if (StringUtil.isBlank(schema)) {
this.schema = tableName.substring(0, indexOf);
this.tableName = tableName.substring(indexOf + 1);
} else {
this.tableName = tableName;
}
} else {
this.tableName = tableName;
}
} }
public Class<?> getEntityClass() { public Class<?> getEntityClass() {

View File

@ -134,8 +134,8 @@ public class TableInfoFactory {
//初始化表名 //初始化表名
Table table = entityClass.getAnnotation(Table.class); Table table = entityClass.getAnnotation(Table.class);
if (table != null) { if (table != null) {
tableInfo.setTableName(table.value());
tableInfo.setSchema(table.schema()); tableInfo.setSchema(table.schema());
tableInfo.setTableName(table.value());
tableInfo.setCamelToUnderline(table.camelToUnderline()); tableInfo.setCamelToUnderline(table.camelToUnderline());
if (table.onInsert().length > 0) { if (table.onInsert().length > 0) {

View File

@ -180,8 +180,8 @@ public class MybatisFlexProcessor extends AbstractProcessor {
TableInfo tableInfo = new TableInfo(); TableInfo tableInfo = new TableInfo();
tableInfo.setEntityName(entityClass); tableInfo.setEntityName(entityClass);
tableInfo.setEntitySimpleName(entityClassName); tableInfo.setEntitySimpleName(entityClassName);
tableInfo.setTableName(table.value());
tableInfo.setSchema(table.schema()); tableInfo.setSchema(table.schema());
tableInfo.setTableName(table.value());
tableInfo.setEntityComment(elementUtils.getDocComment(entityClassElement)); tableInfo.setEntityComment(elementUtils.getDocComment(entityClassElement));
// 生成 TableDef 文件 // 生成 TableDef 文件

View File

@ -78,7 +78,17 @@ public class TableInfo {
} }
public void setTableName(String tableName) { public void setTableName(String tableName) {
this.tableName = tableName; int indexOf = tableName.indexOf(".");
if (indexOf > 0) {
if (schema == null || schema.trim().length() == 0) {
this.schema = tableName.substring(0, indexOf);
this.tableName = tableName.substring(indexOf + 1);
} else {
this.tableName = tableName;
}
} else {
this.tableName = tableName;
}
} }
public String getSchema() { public String getSchema() {