diff --git a/mybatis-flex-codegen/src/main/resources/templates/enjoy/tableDef.tpl b/mybatis-flex-codegen/src/main/resources/templates/enjoy/tableDef.tpl index 6ed6371c..d9c35f6f 100644 --- a/mybatis-flex-codegen/src/main/resources/templates/enjoy/tableDef.tpl +++ b/mybatis-flex-codegen/src/main/resources/templates/enjoy/tableDef.tpl @@ -4,7 +4,7 @@ package #(packageConfig.tableDefPackage); import com.mybatisflex.core.query.QueryColumn; -import com.mybatisflex.core.query.QueryTable; +import com.mybatisflex.core.table.TableDef; #if(jdkVersion >= 14) import java.io.Serial; @@ -16,7 +16,7 @@ import java.io.Serial; * @author #(javadocConfig.getAuthor()) * @since #(javadocConfig.getSince()) */ -public class #(tableDefClassName) extends QueryTable { +public class #(tableDefClassName) extends TableDef { #if(jdkVersion >= 14) @Serial diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/table/TableDef.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/table/TableDef.java new file mode 100644 index 00000000..55b94d30 --- /dev/null +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/table/TableDef.java @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). + *
+ * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *
+ * http://www.apache.org/licenses/LICENSE-2.0 + *
+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.mybatisflex.core.table; + +import com.mybatisflex.core.query.QueryTable; + +/** + * 表定义,内包含字段。 + * + * @author 王帅 + * @since 2024-03-11 + */ +@Deprecated +public abstract class TableDef extends QueryTable { + + protected TableDef(String schema, String tableName) { + super(schema, tableName); + } + + protected TableDef(String schema, String tableName, String alias) { + super(schema, tableName, alias); + } + + /** + * 使用 {@link #getName()} 替代。 + * + * @return 表名 + */ + @Deprecated + public String getTableName() { + return name; + } + +} diff --git a/mybatis-flex-core/src/test/java/com/mybatisflex/coretest/AccountSqlTester.java b/mybatis-flex-core/src/test/java/com/mybatisflex/coretest/AccountSqlTester.java index 2560df07..f3d59222 100644 --- a/mybatis-flex-core/src/test/java/com/mybatisflex/coretest/AccountSqlTester.java +++ b/mybatis-flex-core/src/test/java/com/mybatisflex/coretest/AccountSqlTester.java @@ -54,7 +54,16 @@ public class AccountSqlTester { .from(ar) .leftJoin(a1).on(a1.ID.eq(ar.ACCOUNT_ID)) .leftJoin(a2).on(a2.ID.eq(ar.ACCOUNT_ID)); - System.out.println(SqlFormatter.format(queryWrapper.toSQL())); + String sql = SqlFormatter.format(queryWrapper.toSQL()); + Assert.assertEquals("SELECT\n" + + " ` ar `.` content `,\n" + + " ` a1 `.` id `,\n" + + " ` a2 `.` age `\n" + + "FROM\n" + + " ` tb_article ` AS ` ar `\n" + + " LEFT JOIN ` tb_account ` AS ` a1 ` ON ` a1 `.` id ` = ` ar `.` account_id `\n" + + " LEFT JOIN ` tb_account ` AS ` a2 ` ON ` a2 `.` id ` = ` ar `.` account_id `", sql); + System.out.println(sql); } @Test diff --git a/mybatis-flex-processor/src/main/java/com/mybatisflex/processor/builder/ContentBuilder.java b/mybatis-flex-processor/src/main/java/com/mybatisflex/processor/builder/ContentBuilder.java index 17f80dbc..8b1d04f8 100644 --- a/mybatis-flex-processor/src/main/java/com/mybatisflex/processor/builder/ContentBuilder.java +++ b/mybatis-flex-processor/src/main/java/com/mybatisflex/processor/builder/ContentBuilder.java @@ -66,9 +66,9 @@ public class ContentBuilder { StringBuilder content = new StringBuilder("package "); content.append(tableDefPackage).append(";\n\n"); content.append("import com.mybatisflex.core.query.QueryColumn;\n"); - content.append("import com.mybatisflex.core.query.QueryTable;\n\n"); + content.append("import com.mybatisflex.core.table.TableDef;\n\n"); content.append("// Auto generate by mybatis-flex, do not modify it.\n"); - content.append("public class ").append(tableDefClassName).append(" extends QueryTable {\n\n"); + content.append("public class ").append(tableDefClassName).append(" extends TableDef {\n\n"); //TableDef 类的属性名称 String tableDefPropertyName = null;