使用mybatisplus进行分页查询total总为0的原因
分页查询代码如下,数据能查询出来,但是分页的total总是为0。经过多次调试,发现查询的过程中没有进入分页拦截器(PaginationInterceptor),原来是容器中缺少了这个bean:解决办法:只需要在容器中添加这个bean就行了......
·
使用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();
}
}
更多推荐
已为社区贡献1条内容
所有评论(0)