使用mybatisplus进行分页查询total总为0的原因

使用mybatisplus进行分页查询total总为0的原因

分页查询代码如下,数据能查询出来,但是分页的total总是为0。经过多次调试,发现查询的过程中没有进入分页拦截器(PaginationInterceptor),原来是容器中缺少了这个bean:

public PageResult<OrderVO> findOrderList(Integer page, Integer rows, Integer status) {
        //获取用户id
        Long userId = UserHolder.getUserId();

        //分页查询
        Order order = new Order();
        order.setUserId(userId);
        if (status != null){
            order.setStatus(status);
        }
        QueryWrapper<Order> wrapper = new QueryWrapper<>(order);
        IPage<Order> iPage = new Page<>(page,rows);
        iPage = orderMapper.selectPage(iPage, wrapper);

        //根据订单id查询订单详情列表
        List<Order> orderList = iPage.getRecords();

        List<OrderVO> list = new ArrayList<>();
        orderList.forEach(order2 -> {
            OrderDetail orderDetail = new OrderDetail();
            orderDetail.setOrderId(order2.getOrderId());
            Wrapper wrapper2 = Wrappers.query(orderDetail);
            List<OrderDetail> orderDetails = orderDetailMapper.selectList(wrapper2);
            OrderVO orderVO = BeanHelper.copyProperties(order2, OrderVO.class);
            orderVO.setDetailList(orderDetails);
            list.add(orderVO);
        });

        PageResult<OrderVO> pageResult = new PageResult<>(
                iPage.getTotal(),
                iPage.getPages(),
                list
        );
        return pageResult;
    }

解决办法:只需要在容器中添加这个bean就行了

public class LyOrderApplication {
    public static void main(String[] args) {
        SpringApplication.run(LyOrderApplication.class,args);
    }

    @Bean
    public PaginationInterceptor paginationInterceptor(){
        return new PaginationInterceptor();
    }
}
  • 11
    点赞
  • 15
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值