zoukankan      html  css  js  c++  java
  • 写通用工具类场景1

    utilsResultVOUtil.java

    public class ResultVOUtil {
    
        public static ResultVO success(Object object) {
            ResultVO resultVO = new ResultVO();
            resultVO.setData(object);
            resultVO.setCode(0);
            resultVO.setMsg("成功");
            return resultVO;
        }
    
        public static ResultVO success() {
            return success(null);
        }
    
        public static ResultVO error(Integer code, String msg) {
            ResultVO resultVO = new ResultVO();
            resultVO.setCode(code);
            resultVO.setMsg(msg);
            return resultVO;
        }
    }

    应用:   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);
        }
    
    }
  • 相关阅读:
    鬼斧神工---计算机的开机启动过程
    微服务之日志落盘设计
    微服务架构设计
    一条SQL语句执行得很慢的原因有哪些?
    996:只要能活着就好,不管活得多么糟糕
    事务隔离性与隔离级别
    数据库悲观锁与乐观锁
    解决百度网盘(百度云)分享链接不存在失效、分享的文件已经被取消的问题
    宁撞金钟一下,不打破鼓三千,IT人要有志气,要进就进大的好的公司
    1430:家庭作业
  • 原文地址:https://www.cnblogs.com/tabCtrlShift/p/9127794.html
Copyright © 2011-2022 走看看