Mybatis-Plus 自定义sql

使用springboot整合mybatis-plus(自定义sql查询)

导入依赖(注意:mybatis-plus的版本要大于3.1.2,这里使用的是3.2.0,不然会报错)

pom.xml

 <!--    mybatis-plus-->
        <dependency>
            <groupId>com.baomidou</groupId>
            <artifactId>mybatis-plus-boot-starter</artifactId>
            <version>3.2.0</version>
        </dependency>

 

实体类

这里就不贴代码了哈,把自己需要查询的字段放到Vo中就好了。

 

mapper层

 @Select("select member.*,shipping_address.* from member left join shipping_address on member.member_id=shipping_address.member_id")
    IPage<UsersAddressVo> selectUserListPage(Page<UsersAddressVo> page, UsersAddressVo usersAddressVo);

 

service层

    IPage<UsersAddressVo> selectUserListPage(UsersAddressVo usersAddressVo, Integer pageNum, Integer pageSize);

 

service业务实现层

 @Override
    public IPage<UsersAddressVo> selectUserListPage(UsersAddressVo usersAddressVo, Integer pageNum, Integer pageSize) {
        Page<UsersAddressVo> iPage = new Page<UsersAddressVo>(pageNum, pageSize);
        IPage<UsersAddressVo> memberList = memberMapper.selectUserListPage(iPage, usersAddressVo);
        return memberList;
    }

 

controller层

    @GetMapping("/uniteList")
    public TableDataInfo uniteTable(UsersAddressVo usersAddressVo, @RequestParam("pageNum") Integer pageNum, @RequestParam("pageSize") Integer pageSize){
        IPage<UsersAddressVo> memberIPage = memberService.selectUserListPage(usersAddressVo, pageNum, pageSize);
        List<UsersAddressVo> records = memberIPage.getRecords();
        return getDataTable(records);
    }

 

本地测试

 @Test
    public void contextLoads() {
        Page<UsersAddressVo> pages=new Page<>(1,10);
        memberMapper.selectUserListPage(pages,null);

    }

 

postman测试如下:

 

  如遇到问题进qq群讨论:837146509

 

posted @ 2020-10-08 18:12  安详的苦丁茶  阅读(9089)  评论(0编辑  收藏  举报