zoukankan      html  css  js  c++  java
  • 解决PageHelper.startPage(page, size)后,关于PageInfo的total等属性不正确等问题

    在解决PageHelper.startPage(page, size);的位置问题后,又遇到total等信息错误,主要还是不细心,两个不同的List实例化进PageInfo,不能混在一起,同时要确保这两个List的PageInfo相同(例如:total等page信息相同),才能 pageInfo.setList(stockGoodsDtos);

    问题代码:

    Controller.java

    public Wrapper<PageInfo<StockGoodsDto>> getStockGoodsByCondition(@RequestBody ShopGoods shopGoods,
                                                                     @ApiParam(name = "page", value = "分页值", defaultValue = "0") @RequestParam(defaultValue = "0") Integer page,
                                                                     @ApiParam(name = "size", value = "每分页返回的记录数", defaultValue = "0") @RequestParam(defaultValue = "0") Integer size) {
            List<StockGoodsDto> list = shopGoodsService.getStockGoodsByCondition(shopGoods, page, size);
            PageInfo pageInfo = new PageInfo(list);
            return WrapMapper.ok(pageInfo);
        }
    

    ServiceImpl.java

    public List<StockGoodsDto> getStockGoodsByCondition(ShopGoods shopGoods, Integer page , Integer size) {
            List<StockGoodsDto> stockGoodsDtos = new ArrayList<>();
            ...
            PageHelper.startPage(page, size);
            List<ShopGoods> shopGoodsList = shopGoodsMapper.getStockGoodsByCondition(shopGoods, specIds);
            if (shopGoodsList == null || shopGoodsList.size() == 0) {
                PageInfo pageInfo = new PageInfo(stockGoodsDtos);
                return pageInfo;
            }
            for (ShopGoods goods : shopGoodsList) {
                StockGoodsDto stockGoodsDto = new StockGoodsDto();
                stockGoodsDto.setShopGoods(goods);
                for (ProdSpecInfoDto specInfoDto : prodSpecInfoDtos) {
                    if (goods.getProductId().equals(specInfoDto.getSpecId())) {
                        stockGoodsDto.setProdSpecInfoDto(specInfoDto);
                        stockGoodsDtos.add(stockGoodsDto);
                    }
                }
            }
            return stockGoodsDtos;
        }
    

    修改后,正确代码:

    Controller.java

    public Wrapper<PageInfo<StockGoodsDto>> getStockGoodsByCondition(@RequestBody ShopGoods shopGoods,
                                                                     @ApiParam(name = "page", value = "分页值", defaultValue = "0") @RequestParam(defaultValue = "0") Integer page,
                                                                     @ApiParam(name = "size", value = "每分页返回的记录数", defaultValue = "0") @RequestParam(defaultValue = "0") Integer size) {
            return WrapMapper.ok(shopGoodsService.getStockGoodsByCondition(shopGoods, page, size));
        }
    

    ServiceImpl.java

    public PageInfo<StockGoodsDto> getStockGoodsByCondition(ShopGoods shopGoods, Integer page , Integer size) {
            List<StockGoodsDto> stockGoodsDtos = new ArrayList<>();
            ...
            PageHelper.startPage(page, size);
            List<ShopGoods> shopGoodsList = shopGoodsMapper.getStockGoodsByCondition(shopGoods, specIds);
            if (shopGoodsList == null || shopGoodsList.size() == 0) {
                PageInfo pageInfo = new PageInfo(stockGoodsDtos);
                return pageInfo;
            }
            for (ShopGoods goods : shopGoodsList) {
                StockGoodsDto stockGoodsDto = new StockGoodsDto();
                stockGoodsDto.setShopGoods(goods);
                for (ProdSpecInfoDto specInfoDto : prodSpecInfoDtos) {
                    if (goods.getProductId().equals(specInfoDto.getSpecId())) {
                        stockGoodsDto.setProdSpecInfoDto(specInfoDto);
                        stockGoodsDtos.add(stockGoodsDto);
                    }
                }
            }
            PageInfo pageInfo = new PageInfo(shopGoodsList);
            pageInfo.setList(stockGoodsDtos);
            return pageInfo;
        }
    
  • 相关阅读:
    k8s service定义与创建
    k8s service存在的意义
    k8s job控制器-执行一次性任务
    k8s CronJob定时任务
    k8s Daemonset功能
    k8s deployment控制器Replicaset
    k8s deployment删除
    k8s deployment控制器水平扩容
    k8s deployment发布失败回滚
    k8s deployment控制器:滚动升级 平滑过渡 零停机
  • 原文地址:https://www.cnblogs.com/zys-blog/p/10209977.html
Copyright © 2011-2022 走看看