/** * 订单分页查询 * @param page * @param pageSize * @return */ @GetMapping("/userPage") public R<Page<OrdersDto>> page(Integer page, Integer pageSize){ //创建分页构造器 Page<Orders> pageInfo = new Page<>(page, pageSize); LambdaQueryWrapper<Orders> queryWrapper = new LambdaQueryWrapper<>(); queryWrapper.eq(Orders::getUserId, BaseContext.getCurrentId()); queryWrapper.orderByDesc(Orders::getOrderTime); orderService.page(pageInfo, queryWrapper); Page<OrdersDto> page1 = new Page<>(page, pageSize); BeanUtils.copyProperties(pageInfo, page1, "records"); //将每个order和对应的orderDetail封装成orderDto List<Orders> records = pageInfo.getRecords(); List<OrdersDto> list = records.stream().map((item) -> { OrdersDto ordersDto = new OrdersDto(); BeanUtils.copyProperties(item, ordersDto); LambdaQueryWrapper<OrderDetail> wrapper = new LambdaQueryWrapper<>(); wrapper.eq(OrderDetail::getOrderId, ordersDto.getId()); List<OrderDetail> orderDetails = orderDetailService.list(wrapper); ordersDto.setOrderDetails(orderDetails); return ordersDto; }).collect(Collectors.toList()); page1.setRecords(list); return R.success(page1); }
标签:分页,pageSize,ordersDto,Page,查询,订单,new,page,page1 From: https://www.cnblogs.com/fxzm/p/17223432.html