java常用数据格式转化,类似数据库group by cube rollup


java常用数据格式转化,类似数据库group by cube rollup
单循环一条sql返回格式如:List<Map<String, List<Record>>>

List<Record> operationList = operationService.getByUserId(getCurrentUserId(), "qxpt");
List<Map<String, Object>> showList = new ArrayList<Map<String, Object>>();
List<Record> oList = null;//operationClass下的operation
Map<String, Object> classMap = new HashMap<String, Object>();
for (Record o : operationList) {
if (!classMap.containsKey(o.getStr("class_name"))) {
oList = new ArrayList<Record>();
if (!classMap.isEmpty()) {
showList.add(classMap);
}
classMap = new HashMap<String, Object>();
}
oList.add(o);
classMap.put(o.getStr("class_name"), oList);//单循环持续更新oList
}
showList.add(classMap);

dataMap.put("showList", showList);
renderJson(dataMap);

猜你喜欢

转载自www.cnblogs.com/YuyuanNo1/p/9999596.html