使用MybatisPlus查询的sql,返回的必须是一个对应表实体的泛型分页数据
我们给前端返回只需返回VO,我们可能会循环进行对象复制从新赋值
优化:MybatisPlus分页对象有直接转换的方法

<>优化前
// 最终分页对象 Page<ResultVO> resultPage = new Page<ResultVO>(); List<ResultVO>
resultList= new ArrayList<ResultVO>(); // 使用MybatisPlus查询 Page<
PayTradeOrderEntity> page = this.selectPage( new Query<PayTradeOrderEntity>(
params).getPage(), null); // 循环 List<PayTradeOrderEntity> records = page.
getRecords(); for (PayTradeOrderEntity record : records) { ResultVO vo = new
ResultVO(); BeanUtil.copyProperties(record, vo); resultList.add(vo); }
resultPage.setRecords(resultList); resultPage.setCurrent(page.getCurrent());
resultPage.setSize(page.getSize()); resultPage.setTotal(page.getTotal());
<>优化后
// 使用MybatisPlus查询...... Page<InterestEntity> resultPage = new Page(); //
最终返回分页对象 IPage<InterestProcessVO> convertPage = resultPage.convert(result -> {
InterestProcessVO vo = new InterestProcessVO(); BeanUtil.copyProperties(result,
vo) return vo; });
注意:分页转换器方法体必须使用返回值

技术
下载桌面版
GitHub
百度网盘(提取码:draw)
Gitee
云服务器优惠
阿里云优惠券
腾讯云优惠券
华为云优惠券
站点信息
问题反馈
邮箱:ixiaoyang8@qq.com
QQ群:766591547
关注微信