yulichang / mybatis-plus-join

支持连表查询的mybatis-plus,mybatis-plus风格的连表操作提供wrapper.leftJoin(),wrapper.rightJoin()等操作
https://yulichang.github.io/mybatis-plus-join-doc/
Apache License 2.0
971 stars 113 forks source link

子查询 selectSub 支持动态表名吗 #115

Closed yixingang0525 closed 1 month ago

yixingang0525 commented 2 months ago

当前使用版本(必填,否则不予处理)

1.4.10

实际sql如下: 其中user_tag_151 为动态表名 SELECT tag.*, (SELECT COUNT(1) FROM user_tag_151 t1 WHERE t1.tag_id = tag.tag_id) AS tag_count FROM tag;

代码写法: MPJLambdaWrapper tagMPJLambdaWrapperX = new MPJLambdaWrapper() .selectAll(TagDO.class) .selectSub(UserTagDO.class, w -> w.selectCount(UserTagDO::getTagId, TagRespDTO::getTagMarkCount) .setTableName(name -> name + "_151" ), UserTagDO::getTagId)

控制台打印sql中,子查询中的表并未拼接 '_151' 异常提示表不存在

但是使用leftJoin 动态设置表名却是可以的 MPJLambdaWrapper userDOMPJLambdaWrapper = new MPJLambdaWrapper() .selectAll(TagDO.class) .selectCount(UserTagDO::getTagId,TagRespDTO::getTagMarkCount) .leftJoin(UserTagDO.class, on -> on .eq(UserTagDO::getTagId, TagDO::getTagId) .setTableName(name -> name + "_151")) .groupBy(TagDO::getTagId);

子查询 selectSub 是还不支持动态表名吗?

yulichang commented 2 months ago

下个版本加上