List.forEach()使用方法

前言

不想写,直接看代码吧

正文

List gridTeamTemplates = gridTeamTemplateMapper.selectTeam(s);
      
List gridTeamTemplateVOList = new ArrayList<>();
//这里用了java8的lambda表达式,grid就是传入参,也可以写成(GridTeamTemplate grid)->{}
gridTeamTemplates.forEach(grid-> {
    GridTeamTemplateVO gridTeamTemplateVO = new GridTeamTemplateVO();
    BeanUtil.copyProperties(grid,gridTeamTemplateVO);
    List list1 = new ArrayList();
    if (grid.getIsProvince()) {
        ist1.add("省");
    }
    gridTeamTemplateVO.setHierarchy(list1);
    gridTeamTemplateVOList.add(gridTeamTemplateVO);
});

你可能感兴趣的:(util,java,lambda)