mybatis plus 多表联查

1、先定义mapper中的方法

/**
     * 获取地址
     */
    @Select("SELECT a.id," +
            "a.mid," +
            "m.membername," +
            "a.address," +
            "a.contact," +
            "a.mobile," +
            "a.isdefault," +
            "a.createDate," +
            "a.createman," +
            "a.modifyDate," +
            "a.modifyman," +
            "a.deleteDate," +
            "a.deleteman," +
            "a.softdel" +
            " FROM memberaddress a, member m" +
            " ${ew.customSqlSegment}")
    Page<Memberaddress> getMemberaddressPage(IPage<member_address> page, @Param("ew") Wrapper<member_address> wrapper);

注意:customSqlSegment这个不能改,一定就会出错哦, 应该是系统预留变量。

2、service中调用方法

@Override
    public Page<member_address> getMemberaddressList(member_address address) {
        QueryWrapper<member_address> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("a.soft_del",0)
                .like(address.getMembername()!=null&&!address.getMembername().equals(""),"m.membername",address.getMembername())
                .apply("a.mid = m.id")
                .orderByDesc("a.create_date");
        return addressMapper.getMemberaddressPage(new Page<>(address.getPage(), address.getPageSize()),queryWrapper);
    }

说明:其实这里还是用的mybatis的方法@Select。

 

 

参考:https://blog.csdn.net/manba_yqq/article/details/125511075

 

posted @ 2022-10-14 11:38  jiduoduo  阅读(1717)  评论(0编辑  收藏  举报