使用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层
@Select("select member.*,shipping_address.* from member left join shipping_address on member.member_id=shipping_address.member_id")
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测试如下: