List<Map<String,Object>> firstList = new ArrayList<Map<String,Object>>(); //定义一个List<Map<String,Object>>集合
Map<String,Object> investMap = new HashMap<String,Object>();//定义一个map对象
firstList = budgetStatisticsByProjectBizc.queryProjectInvestStaticZX(condition);//为List<Map<String,Object>> firstList 赋值
//统计firstList中的数据,存入到investMap对象中
int fieldCount = 0;
BigDecimal expendTotal = BigDecimal.valueOf(0.0);
BigDecimal investTotal = BigDecimal.valueOf(0.0);
Double investTotalDouble = 0.0;
Double expendTotalDouble = 0.0;
for (Map<String, Object> obj : firstList) {
fieldCount += Integer.parseInt(obj.get("fieldCount").toString());
investTotalDouble =(Double) (obj.get("investTotal") == null?0.0:obj.get("investTotal"));
investTotal = investTotal.add( BigDecimal.valueOf(investTotalDouble));
expendTotalDouble =(Double) (obj.get("expendTotal") == null?0.0:obj.get("expendTotal"));
expendTotal = expendTotal.add( BigDecimal.valueOf(expendTotalDouble));
}
investMap.put("fieldCount", fieldCount);
investMap.put("investTotal", investTotal);
investMap.put("expendTotal", expendTotal);
investMap.put("budgetYear", "合计");
//将investMap对象保存到firstList
firstList.add(investMap);
Map集合操作
最新推荐文章于 2024-03-14 08:49:20 发布