MybatisPlus手写sql分页

        最近做的项目因为是使用的sqlserver,分页的写法比mysql复杂很多,所以现在有多表查询的时候需要用到框架自带的分页查询,但之前都是使用的单表的分页查询,那接下来就分享一下多表的分页怎么处理

1.控制层

/**
     * 獲取子企業列表
     */
    @GetMapping("/getCustomerByPid")
    public ReqVo<Page<TBasCustomer>> getCustomerByPid(@RequestParam Integer pid,@RequestParam String name,@RequestParam Integer current,@RequestParam Integer size,HttpServletRequest req){
        ReqVo<Page<TBasCustomer>> reqVo=new ReqVo<>();
        Page<TBasCustomer> page = tBasCustomerService.getCustomerByPid(pid,name,current,size,req);
        reqVo.setData(page);
        return reqVo;
    }

2.实现层

 @Override
    public Page<TBasCustomer> getCustomerByPid(Integer pid, String name,Integer current,Integer size,HttpServletRequest req) {
        Page page =new Page();
        page.setCurrent(current);
        page.setSize(size);
        Integer uid = userUtils.getUserInfo(req).getId();
        Page<TBasCustomer> resultPage =this.baseMapper.getCustomerPageByPid(page,pid,uid,name);
        return resultPage;
    }

3.Mapper

 /**
     * 獲取子企業
     * @param
     * @return
     */
    Page<TBasCustomer> getCustomerPageByPid(Page page,@Param("pid") Integer pid,@Param("uid")Integer uid,@Param("name")String name);

4.xml配置文件

 <select id="getCustomerPageByPid" resultType="io.github.talelin.latticy.model.TBasCustomer">
        select c.* from T_Bas_Customer c inner join T_SysUsersCustomerScope cs on c.id=cs.CustomId where pid=#{pid} and cs.uid=#{uid}
        <if test=' name!=null and name!="" '>
            and c.cname like #{name}
        </if>
    </select>

5.打印结果

MybatisPlus手写sql分页

 6.返回的数据

{
    "code": "200",
    "message": "成功",
    "data": {
        "records": [
            {
                "id": 17375,
                "cname": "海底捞火锅店",
                "ename": null,
                "nickname": null,
                "keyid": "0F5D1B89-2A7C-4505-9F3D-002850CDC075",
                "pid": 10000003
            },
            {
                "id": 17376,
                "cname": "复星诊断科技(上海)有限公司",
                "ename": null,
                "nickname": null,
                "keyid": "4660D9AE-03FA-42A0-A4D8-005DBC808D6A",
                "pid": 10000003
            },
            {
                "id": 17377,
                "cname": "试用企业",
                "ename": null,
                "nickname": null,
                "keyid": "AE2B1857-D777-4B12-BF31-00C1499148A6",
                "pid": 10000003
            },
            {
                "id": 17378,
                "cname": "腾讯云计算(北京)有限责任公司",
                "ename": null,
                "nickname": null,
                "keyid": "E13277ED-B221-4840-9A58-00C1D2745379",
                "pid": 10000003
            },
            {
                "id": 17379,
                "cname": "博彦科技",
                "ename": null,
                "nickname": null,
                "keyid": "ECDD181F-D7D9-4D98-B83F-032FF8B392EA",
                "pid": 10000003
            },
            {
                "id": 17380,
                "cname": "阿斯利康(无锡)贸易有限公司",
                "ename": null,
                "nickname": null,
                "keyid": "908C00A0-ED69-4A7B-8747-08B0F99BD4AB",
                "pid": 10000003
            },
            {
                "id": 17381,
                "cname": "上海药明生物技术有限公司",
                "ename": null,
                "nickname": null,
                "keyid": "638DB1BE-E33B-4438-B236-0925C7B7F2DA",
                "pid": 10000003
            },
            {
                "id": 17382,
                "cname": "阿斯利康医药科技(北京)有限公司",
                "ename": null,
                "nickname": null,
                "keyid": "8FE1BC1C-D2B0-44FD-B5D9-097CF0E8DA34",
                "pid": 10000003
            },
            {
                "id": 17383,
                "cname": "吉县三农国际商贸有限公司",
                "ename": null,
                "nickname": null,
                "keyid": "82AC30F2-8D5E-42D4-B5CB-0B76D3417EB8",
                "pid": 10000003
            },
            {
                "id": 17384,
                "cname": "上海乾扬传媒有限公司",
                "ename": null,
                "nickname": null,
                "keyid": "A5851DB8-B53D-4893-A697-0C0FBE5A63DD",
                "pid": 10000003
            }
        ],
        "total": 204,
        "size": 10,
        "current": 0,
        "orders": [],
        "optimize_count_sql": true,
        "hit_count": false,
        "count_id": null,
        "max_limit": null,
        "search_count": true,
        "pages": 21
    }
}

上一篇:C#基础篇 - 正则表达式入门


下一篇:Android高级面试题:面试十几家公司入职外企后,掌握这几个关键点面试通过率很大