diff --git a/mybatis-plus-join-core/src/main/java/com/github/yulichang/method/mp/SelectObjs.java b/mybatis-plus-join-core/src/main/java/com/github/yulichang/method/mp/SelectObjs.java index 46f12ef..00988ad 100644 --- a/mybatis-plus-join-core/src/main/java/com/github/yulichang/method/mp/SelectObjs.java +++ b/mybatis-plus-join-core/src/main/java/com/github/yulichang/method/mp/SelectObjs.java @@ -27,6 +27,14 @@ public class SelectObjs extends com.baomidou.mybatisplus.core.injector.methods.S copyAndSetTableName(tableInfo, getTableName(tableInfo))); } + @Override + protected String sqlSelectObjsColumns(TableInfo table) { + String selectColumns = super.sqlSelectObjsColumns(table); + return SqlScriptUtils.convertChoose(String.format("%s == null or !(%s instanceof %s)", Constants.WRAPPER, Constants.WRAPPER, MPJBaseJoin.class.getName()), + selectColumns, mpjSqlSelectColumns() + StringPool.SPACE + selectColumns); + } + + @Override protected String sqlWhereEntityWrapper(boolean newLine, TableInfo table) { return SqlScriptUtils.convertChoose(String.format("%s == null or !(%s instanceof %s)", Constants.WRAPPER, Constants.WRAPPER, MPJBaseJoin.class.getName()), diff --git a/mybatis-plus-join-test/test-join/src/main/java/com/github/yulichang/test/join/entity/UserDO.java b/mybatis-plus-join-test/test-join/src/main/java/com/github/yulichang/test/join/entity/UserDO.java index b521975..6d574cd 100644 --- a/mybatis-plus-join-test/test-join/src/main/java/com/github/yulichang/test/join/entity/UserDO.java +++ b/mybatis-plus-join-test/test-join/src/main/java/com/github/yulichang/test/join/entity/UserDO.java @@ -23,7 +23,7 @@ import java.util.Map; @EqualsAndHashCode(callSuper = true) @DynamicTableName @FieldNameConstants -@TableName(value = "`user`") +@TableName(value = "`user`", autoResultMap = true) public class UserDO extends ID implements Serializable { private Integer pid; diff --git a/mybatis-plus-join-test/test-join/src/test/java/com/github/yulichang/test/join/LambdaWrapperTest.java b/mybatis-plus-join-test/test-join/src/test/java/com/github/yulichang/test/join/LambdaWrapperTest.java index 7c6e8d9..e2bdfa3 100644 --- a/mybatis-plus-join-test/test-join/src/test/java/com/github/yulichang/test/join/LambdaWrapperTest.java +++ b/mybatis-plus-join-test/test-join/src/test/java/com/github/yulichang/test/join/LambdaWrapperTest.java @@ -516,6 +516,19 @@ class LambdaWrapperTest { System.out.println(list); } + /** + * 别名测试 + */ + @Test + void testObj() { + ThreadLocalUtils.set("SELECT DISTINCT t1.id FROM `user` t LEFT JOIN `user` t1 ON (t1.pid = t.id) WHERE t.del=false AND t1.del=false"); + MPJLambdaWrapper wrapper = new MPJLambdaWrapper() + .distinct() + .select(UserDO::getId) + .leftJoin(UserDO.class, UserDO::getPid, UserDO::getId); + List list = userMapper.selectObjs(wrapper); + } + @Test void testTableAlias() { ThreadLocalUtils.set("SELECT t.id,\n" +