public List<Record> getRecordlList(String fieldName) { Pattern p = Pattern.compile(fieldName + "\\[\\d+\\].[a-zA-z0-9]+"); Map<String, String[]> parasMap = getRequest().getParameterMap(); String paraKey; Map<String, Map<String, Object>> parasMap2=new HashMap<String, Map<String,Object>>(); for (Entry<String, String[]> e : parasMap.entrySet()) { paraKey = e.getKey(); Matcher m = p.matcher(paraKey); if (m.find()) { String key = paraKey.substring(paraKey.indexOf("[")+1, paraKey.indexOf("]",paraKey.indexOf("[") )); if(parasMap2.containsKey(key)){ Map<String, Object> tmp = parasMap2.get(key); if(StrKit.notBlank(e.getValue()[0])){ tmp.put(paraKey.split("\\.")[1], e.getValue()[0]); parasMap2.replace(key, tmp); } }else{ Map<String, Object> tmp=new HashMap<String, Object>(); if(StrKit.notBlank(e.getValue()[0])){ tmp.put(paraKey.split("\\.")[1], e.getValue()[0]); parasMap2.put(key, tmp); } } } } Iterator<Entry<String, Map<String, Object>>> its = parasMap2.entrySet().iterator(); List<Record> resultList = new ArrayList<Record>(); while(its.hasNext()){ resultList.add(new Record().setColumns(its.next().getValue())); } return resultList; }
简单粗暴写出来的~欢迎拍砖!