JDK1.8新属性lambda

List<ProductInfo> productInfoList = productService.findUpAll();
//精简方法(java8, lambda)
List<Integer> categoryTypeList = productInfoList.stream()
.map(e -> e.getCategoryType())
.collect(Collectors.toList());
List<ProductCategory> productCategoryList = categoryService.findByCategoryTypeIn(categoryTypeList);



        //传统方法
// for (ProductInfo productInfo : productInfoList) {
// categoryTypeList.add(productInfo.getCategoryType());
// }

 

还可以这么写

        List<CartDTO> cartDTOList = orderDTO.getOrderDetailList().stream().map(e ->
                new CartDTO(e.getProductId(), e.getProductQuantity())
        ).collect(Collectors.toList());

 

posted @ 2019-10-12 09:31  我爱si搬砖  阅读(362)  评论(0编辑  收藏  举报