Mybatis-plus: 是不是无法做多表关联查询

Created on 31 Oct 2016  ·  19Comments  ·  Source: baomidou/mybatis-plus

是不是无法做多表关联查询?

Most helpful comment

@whiletrue2009 @Szjz 多表 MP 不会支持,不然就变成 Hibernate 了失去了 mybatis 原有自定义 SQL 灵活性的优势,最佳实践如下:

List<OrderVerify> findByWrapper(@Param("ew") Wrapper wrapper);
<select id="findGymnasiumOrderVerify" resultType="OrderVerify">
        SELECT o.id AS orderId, o.order_no AS orderNo, ...  FROM order o
        LEFT JOIN category c ON o.category_id=c.id
        ${ew.sqlSegment}
</select>

All 19 comments

抱歉,暂不支持多表关联,目前的多表操作请按照传统Mybatis一样写xml、mapper和service。 我们计划在2.0中支持,请期待2.0版本~

这个问题比较大啊,期待早日实现

看了下,已经有v2.0.8了,可以支持了吗?

我也没找到对于联表查询的支持方法

@whiletrue2009 @Szjz 多表 MP 不会支持,不然就变成 Hibernate 了失去了 mybatis 原有自定义 SQL 灵活性的优势,最佳实践如下:

List<OrderVerify> findByWrapper(@Param("ew") Wrapper wrapper);
<select id="findGymnasiumOrderVerify" resultType="OrderVerify">
        SELECT o.id AS orderId, o.order_no AS orderNo, ...  FROM order o
        LEFT JOIN category c ON o.category_id=c.id
        ${ew.sqlSegment}
</select>

@qmdx 明白了。

问下现在支持联表查询了 么

@qmdx 我参考你的DEMO 试了一下,只能添加 left join 表 on 字句1 and 字句2。怎样支持left join 表 on 字句1 and 字句2 where 字句3 and 字句4

现在支持联表查询了 么

多表关联时遇到了一个问题,我在实体类字段上使用@TableField定义了别名,如果使用xml和注解的形式去写多表关联 我需要把每个字段再显示的起别名 才能够注入到实体类中 字段少时还可以,字段多了很不方便 而且以后维护起来也不舒服。有没有猿可以写一个扩展,就是可以让我的多表关联sql里查询出来的字段可以直接被实体类字段上注解识别 这样我的别名就可以都写在一个地方了 -- 感觉很有用处

老大哥现在mybatisPlus已经3.+了请问支持连表查询了吗

@SHDNMD xml 中去做,mp 暂无注解支持计划

好的谢谢

------------------ 原始邮件 ------------------
发件人: "qmdx"notifications@github.com;
发送时间: 2019年6月19日(星期三) 下午3:13
收件人: "baomidou/mybatis-plus"mybatis-plus@noreply.github.com;
抄送: "SHD"704742491@qq.com;"Mention"mention@noreply.github.com;
主题: Re: [baomidou/mybatis-plus] 是不是无法做多表关联查询 (#8)

@SHDNMD xml 中去做,mp 暂无注解支持计划


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or mute the thread.

${ew.sqlSegment}
这个${ew.sqlSegment} 是不是前面少了个WHERE

习惯了orm关联查询,感觉手写sql好多硬编码

@qmdx 我参考你的DEMO 试了一下,只能添加 left join 表 on 字句1 and 字句2。怎样支持left join 表 on 字句1 and 字句2 where 字句3 and 字句4

你可传多个Wrapper,然后用

List<OrderVerify> findByWrapper(@Param("ew1") Wrapper wrapper,@Param("ew2") Wrapper wrapper);
select * from 
  (select *** from a where 1=1 ${ew1.sqlSegment}) a
left join 
  (select **** from b where 1=1 ${ew2.sqlSegment} ) b 
  on a.xx=b.xx

近期基于mybatis-plus扩展写了个基于注解的多表关联查询功能,新增了5个注解,支持单主键场景下的一对多、多对多多表关联查询功能。
大言不惭,不知道baomidou的大佬是否有意愿合并PR,如果有意愿的话,我春节后我可以开始着手准备跟mybatis-plus做一些融合开发。

不会支持

不会支持
好的,了解啦。

Was this page helpful?
0 / 5 - 0 ratings

Related issues

FelixLiuSheng picture FelixLiuSheng  ·  8Comments

UnknownDeveloper007 picture UnknownDeveloper007  ·  8Comments

wangyaochong picture wangyaochong  ·  9Comments

sunqqqq picture sunqqqq  ·  3Comments

mloveing picture mloveing  ·  9Comments