yulichang / mybatis-plus-join

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

[错误报告]: 连表查询时,SQL语句里没有给表设置默认别名,但是字段设置了别名,导致SQL报错。 #214

Closed gordon-lang closed 4 weeks ago

gordon-lang commented 1 month ago

确认

当前程序版本

1.5.1

问题描述

我的serviceImpl里的查询代码如下: List<Map<String, Object>> maps = houseMapper.selectMaps( new MPJLambdaWrapper<ConfigHouse>() .select(ConfigHouse::getId, ConfigHouse::getName) .selectAs(ConfigBuilding::getName, "buildingName") .leftJoin(ConfigBuilding.class, ConfigBuilding::getId, ConfigHouse::getBuildingId) .eq(ConfigHouse::getId, "1846754161923682305")); 使用MPJLambdaWrapper进行连表查询,查询语句里对字段设置了“t”的别名,但是表没有给别名,不知道什么原因,然后只能SQL报错,下面控制台执行日志也打印了“SELECT t.id,t.name,t1.NAME AS buildingName FROM config_house WHERE (t.id = ?)”,令人费解;

详细堆栈日志

14:49:19.895 [http-nio-8097-exec-1] INFO  o.a.c.c.C.[.[.[/] - [log,173] - Initializing Spring DispatcherServlet 'dispatcherServlet'
14:49:20.546 [http-nio-8097-exec-1] DEBUG c.s.b.m.C.selectMaps - [debug,137] - ==>  Preparing: SELECT t.id,t.name,t1.NAME AS buildingName FROM config_house WHERE (t.id = ?)
14:49:20.547 [http-nio-8097-exec-1] DEBUG c.s.b.m.C.selectMaps - [debug,137] - ==> Parameters: 1846754161923682305(String)
yulichang commented 1 month ago

使用selectJoinMaps