New features of java8 lambda expression

Lambda expressions are very powerful. . . . . . . . .
Here I only record the scenes I used when I met.

scene 1

: The objects in a list are objects. We need to extract the attributes of the objects and install them in the list. Can do this

 //查询上架的商品
 List<ProductInfo> productInfoList = productService.findUpAll();
 //查询上架的商品所对应的类目
 List<Integer> categoryTypeList = productInfoList.stream().map(productInfo ->    productInfo.getCategoryType()).collect(Collectors.toList());

The spring framework provides me with a tool class that can copy the attribute value of one class to the attribute of another class, provided that the field names of the two classes are the same.

BeanUtils.copyProperties(productInfo, productInfoVO);      //把productInfo  copy  到productInfoVO 对象里面去
Published 281 original articles · 50 praises · 450,000 views +

Guess you like

Origin blog.csdn.net/lzh657083979/article/details/79426966