@Data
public class SysDept {
private String deptId;
private String deptName;
private List<SysDeptImage> sysDeptImage;
}
@Data
public class SysDeptImage {
private String imageId;
private String deptId;
private String imageName;
priavte String imagePath;
}
//数据库中查出部门信息
List<SysDept> sysDeptList = sysDeptMapper.selectSysDept(new SysDept());
//过滤出部门id
List<String> deptIds = sysDeptList.stream().map(SysDept::getDeptId).collect(Collectors.toList());
//根据部门id查出所有部门的图片信息
List<SysDeptImage> sysDeptImageList = sysDeptMapper.selectSysDeptImage(deptIds);
//根据部门编号分组展示成一个map
Map<String,List<SysDeptImage> sysDeptImageMap = sysDeptImageList.stream().collect(Collectors.groupingBy(SysDeptImage::getDeptId));
//从map中取值,然后赋值给部门的图片信息
sysDeptList.foreach(s -> s.setSysDeptImage(sysDeptImageMap.getOrgDefault(s.getDeptId),new ArrayList()))