组装数据
1、使用Map组装 特点key唯一
将一个LIst<MergeRow>组装成以下格式:
Map<String, List<MergeRow>> result = Maps.newLinkedHashMap();
说明:MergeRow是一个对象 根据其中的某一个字段进行组装 例如:网点waybill_no
思路:
1、首先设计组装成的形式:
Map<String, List<MergeRow>> result = Maps.newLinkedHashMap();
2、代码思路:循环List<MergeRow>
判断result中是否含有waybill_no这个key 第一次肯定是不含有
那么创建一个mergeRows = Lists.newArrayList();并且put到result中result.put(waybillNo, mergeRows);
后面的MergeRow对象的waybill_no如果和 result的key一致 那么add进去
Map<String, List<MergeRow>> result = Maps.newLinkedHashMap();
for (MergeRow mergeRow : rows) {
String waybillNo = (String) mergeRow.toRow().get("waybill_no");
if (StringUtils.isBlank(waybillNo)) {
continue;
}
//判断是否存在
List<MergeRow> mergeRows = result.get(waybillNo);