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,8 +150,18 @@ public class TableInfo {
}
public void setTableName(String 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() {
return entityClass;

View File

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

View File

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

View File

@ -78,8 +78,18 @@ public class TableInfo {
}
public void setTableName(String 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() {
return schema;