级联查询(list内容被最后一次循环覆盖)
Posted 爱豆技术部
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了级联查询(list内容被最后一次循环覆盖)相关的知识,希望对你有一定的参考价值。
级联查询(list内容被最后一次循环覆盖)
List<WmWarehouse> wmWarehouses = wmWarehouseMapper.selectWmWarehouseList(new WmWarehouse());
List<ThreadData> options = new ArrayList<>();
WmStorageArea wmStorageArea = new WmStorageArea();
WmStorageLocation wmStorageLocation = new WmStorageLocation();
List<SecondData> children = new ArrayList<>();
for (int i = 0; i < wmWarehouses.size(); i++)
//必须在for中初始化实例:每次都是一个新的变量用来储存你需要的值
ThreadData threadData = new ThreadData();
String warehouseName = wmWarehouses.get(i).getWarehouseName();//仓库的结构
String warehouseId = wmWarehouses.get(i).getWarehouseId();
threadData.setValue(warehouseId);//value是key,
//每次都是一个新的变量用来储存你需要的值
threadData.setLabel(warehouseName);
wmStorageLocation.setWarehouseId(warehouseId);
List<WmStorageLocation> storageLocations = wmStorageLocationMapper.selectWmStorageLocationList(wmStorageLocation);
for (int j = 0; j < storageLocations.size(); j++)
//库区的结构
SecondData secondData = new SecondData();
String locationId = storageLocations.get(j).getLocationId();
String locationName = storageLocations.get(j).getLocationName();
secondData.setValue(locationId);
secondData.setLabel(locationName);
wmStorageArea.setLocationId(locationId);
List<WmStorageArea> wmStorageAreas = wmStorageAreaMapper.selectWmStorageAreaList(wmStorageArea);
List<FirstData> children1 = new ArrayList<>();
for (int k = 0; k < wmStorageAreas.size(); k++)
FirstData firstData = new FirstData();
String areaId = wmStorageAreas.get(k).getAreaId();
String areaName = wmStorageAreas.get(k).getAreaName();
firstData.setValue(areaId);
firstData.setLabel(areaName);
children1.add(firstData);
secondData.setChildren(children1);
children.add(secondData);
threadData.setChildren(children);
options.add(threadData);
以上是关于级联查询(list内容被最后一次循环覆盖)的主要内容,如果未能解决你的问题,请参考以下文章
java ArrayList循环增加add(对象)总是被最后一个覆盖,把new 对象放在循环里面也是,求大神帮忙
关于Python中,循环后使用list.append(),数据被覆盖的问题