基于注解的mybatis-plus多表查询

mybatis-plus多表查询

在实际项目开发中使用mybatis-plus和springboot结合的方式,但是实际操作需要多表查询,下面简单记载下自己多表查询的方式
1.在Dao层中类给需要联表查询的函数添加注释@Select

@Select("select a.order_id,a.order_price,a.order_date,a.pay_mode,b.role_province_names,b.use_end_time," +
            " b.member_type,case a.pay_mode when 0 then '微信' when 1 then '支付宝'" +
            " when 2 then '银联' when 10 then '系统操作' end as pay_mode_cn," +
            " case b.member_type when 1 then '省级VIP' when 2 then '高级VIP' when 3 then '项目VIP' " +
            " end as member_type_cn from t_order a inner join t_member b on " +
            " a.cust_id = b.cust_id where a.cust_id = #{custId}")
    public List<OrderVo> getOrders(Integer custId) throws Exception;

这里的sql语句和mybatis的书写方法是一样的

2.在实现类中通过baseMapper调用这个函数即可

@Override
    public List<OrderVo> getOrders(Integer custId) throws Exception {
        return this.baseMapper.getOrders(custId);
    }

3.需要注意的是查询字段必须和实体类中的属性一一对应

4.controller类中直接调用实现类函数可以得到返回结果

List<OrderVo> getOrders = orderService.getOrders(custId);

但是个人感觉这种联表查询方式还是比较麻烦的,如果还有更好的方式感谢告知!

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值