Mybatis-Plus 多表查问分页
1. 在mapper外面定义方法
/* 第一种写法@Select("select c.* from tb_staff_customer_relation as scr left join tb_customer as c on scr.customer_id = c.id ${ew.customSqlSegment}")List<Customer> getListById(Page<Customer> page, @Param(Constants.WRAPPER) Wrapper wrapper);*//** * 第二种写法 */@Select("select c.* from tb_staff_customer_relation as scr left join tb_customer as c on scr.customer_id = c.id ${ew.customSqlSegment}")IPage<Customer> getListById(Page page, @Param(Constants.WRAPPER) Wrapper wrapper);
解释:
- page参数 com.baomidou.mybatisplus.extension.plugins.pagination.Page 须要导入此包
- wrapper参数 com.baomidou.mybatisplus.core.conditions.Wrapper 须要导入此包
- 固定写法,至于怎么失效的,我也不晓得呢
2. service调用mapper外面的办法
/** * 第二种写法,不应用page类 返回后果应用ipage */@Overridepublic List<CustomerResponseVo> getListByStaffId(int staff_id, int page, int limit) { QueryWrapper<Customer> wrapper = new QueryWrapper<>(); // 查问条件 wrapper.eq("scr.staff_id", staff_id); // 后果集排序 wrapper.orderByDesc("c.id"); IPage<Customer> customerIPage = staffCustomerRelationMapper.getListById(new Page(page, limit), wrapper); ArrayList<CustomerResponseVo> arrayList = new ArrayList<>(); // 获取后果集 List<Customer> list = customerIPage.getRecords(); // 拼装返回数据 for (Customer customer : list) { CustomerResponseVo responseVo = GemBeanUtils.copyProperties(customer, CustomerResponseVo.class); arrayList.add(responseVo); } return arrayList;}
java初学人员记录笔记,欢送大佬指教