做天津杰超项目中赛事活动作品审核中写的一段代码:
1 //获取全部作品 2 ActivityProductionQueryCommond productionQueryCommond=new ActivityProductionQueryCommond(); 3 productionQueryCommond.setSearchProductionWorksId(worksValidCommond.getProductionWorksId()); 4 List<ActivityProductionValidCommond> productionValidCommonds=(List<ActivityProductionValidCommond>) this.activityProductionService
.findAllList(productionQueryCommond); 5 //循环分组 6 Map<String, List<ActivityProductionValidCommond>> proHashMap=new HashMap<String, List<ActivityProductionValidCommond>>(); 7 for (ActivityProductionValidCommond production : productionValidCommonds) { 8 if(proHashMap.containsKey(production.getProductionGroupId())) { 9 proHashMap.get(production.getProductionGroupId()).add(production); 10 }else { 11 List<ActivityProductionValidCommond> proList=new ArrayList<ActivityProductionValidCommond>(); 12 proList.add(production); 13 proHashMap.put(production.getProductionGroupId(), proList); 14 } 15 } 16 List<String> keyList=new ArrayList<String>(proHashMap.keySet()); 17 Collections.sort(keyList);//key排序 空在最上面 18 Map<String, List<ActivityProductionValidCommond>> proLinkedMap=new LinkedHashMap<String, List<ActivityProductionValidCommond>>(); 19 //生成有序map 20 for (String key : keyList) { 21 if(PropertyUtil.objectNotEmpty(key)) { 22 ProductionGroupValidCommond group=this.productionGroupService.find(key); 23 key=group.getProductionGroupName(); 24 }else { 25 key="未分组"; 26 } 27 proLinkedMap.put(key, proHashMap.get(key)); 28 }
写的不好。请大神们指正。我改。