字段中有个 1,2,3,4
形式的varchar LocationTypeIds字段
前端携带相应的字段中的某个值typeId
进行接口请求
期望获得LocationTypeId
有typeId
值的记录
locationInfoDTOList
是List
类型
LabelValue children = new LabelValue();for(int i =0;i//所有的子集LabelValue children = new LabelValue();for (String temp:locationInfoDTOList.get(i).getLocationTypeIds().split(",")) {if(Objects.equals(typeId, temp)){//如果某个子集的ids包括的上传的,那就把子集放在父里children.setLabel(locationInfoDTOList.get(i).getLocationName());children.setValue(locationInfoDTOList.get(i).getId());children.setKey(locationInfoDTOList.get(i).getLocationTypeIds());parent.add(children);}}}
locationInfoDTOList.stream()
.filter(info -> info.getLocationTypeIds().contains(typeId))
.map(info -> new LabelValue(info.getId(),info.getLocationTypeIds(),info.getLocationName(),info.getId()))
.collect(Collectors.toList())
stream()
方法将列表转换为一个流对象filter()
方法过滤出包含指定 typeId
的地点信息对象->
将输入参数 info
映射到一个布尔值结果map()
方法将符合条件的地点信息对象转换为新的 LabelValue
对象info
映射到一个 LabelValue
对象LabelValue
对象的构造函数接受四个参数,分别是 id
、locationTypeIds
、locationName
和 id
(id,key,label,value)collect()
方法将转换后的 LabelValue
对象收集到一个新的列表中,并使用 toList()
方法指定收集器类型为列表LabelValue
对象的列表下一篇:点亮LED