java常用資料格式轉化,類似資料庫group by cube rollup
阿新 • • 發佈:2018-11-22
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);