zoukankan      html  css  js  c++  java
  • 拼接VO参数

    controllerBuyerProductController.java

    /**
     * 买点端商品
     */
    @RestController
    @RequestMapping("/buyer/product")
    public class BuyerProductController {
    
        @Autowired
        ProductService productService;
    
        @Autowired
        CategoryService categoryService;
    
        @GetMapping("/list")
        @Cacheable(cacheNames = "product" , key = "#sellerId" , condition = "#sellerId.length() > 3")
        public ResultVO<List<ProductVO>> list(@RequestParam("sellerId") String sellerId) {
            //获取所有上架商品
            List<ProductInfo> productInfoList = productService.findUpAll();
            //获取所有的类目
            List<Integer> categoryTypes = productInfoList.stream()
                    .map(e -> e.getCategoryType())
                    .collect(Collectors.toList());
    
            List<ProductCategory> productCategoryList = categoryService.findByCategoryTypeIn(categoryTypes);
    
            //拼接VO
            List<ProductVO> productVOList = new ArrayList<>();
            for(ProductCategory productCategory : productCategoryList) {
                ProductVO productVO = new ProductVO();
                productVO.setCategoryName(productCategory.getCategoryName());
                productVO.setCategoryType(productCategory.getCategoryType());
    
                List<ProductInfoVO> productInfoVOList = new ArrayList<>();
                for(ProductInfo productInfo : productInfoList) {
                    if(productCategory.getCategoryType().equals(productInfo.getCategoryType())) {
                        ProductInfoVO productInfoVO = new ProductInfoVO();
                        BeanUtils.copyProperties(productInfo , productInfoVO);
                        productInfoVOList.add(productInfoVO);
                    }
                }
    
                productVO.setProductInfos(productInfoVOList);
                productVOList.add(productVO);
            }
    
            return ResultUtils.success(productVOList);
        }
    
    }
  • 相关阅读:
    php 邮件发送开发前期配置
    抛弃传统的curl,使用Guzzle
    TP5.1 分页(带参数传递)
    tp5.1 模型 where多条件查询 like 查询
    xpath 和 jsonpath 解析
    python分布式爬虫框架 --- scrapy-redis
    python爬虫框架——scrapy
    python爬虫 --- urllib
    mysql事务和锁
    mysql数据储存
  • 原文地址:https://www.cnblogs.com/tabCtrlShift/p/9127790.html
Copyright © 2011-2022 走看看