[Ljava.lang.String;cannotbecasttojava.lang.Long;一直报错,通过request.getParameterMap();得到的map里面的value为字符串数组
方法/步骤
1、publicclassPage锓旆痖颧DataextendsHashMapimplementsMap{ privatestatic惺绅寨瞀finallongserialVersionUID=1L; Mapmap=null; HttpServletRequestrequest; publicPageData(HttpServletRequestrequest){ this.request=request; Mapproperties=request.getParameterMap(); MapreturnMap=newHashMap(); Iteratorentries=properties.entrySet().iterator(); Map.Entryentry; Stringname=""; Stringvalue="";
2、while(entries.hasNext()){entry=(Map.Entry)entries.next();name=(String)entry.getKey();ObjectvalueObj=entry.getValue();if(null==valueObj){value="";}elseif(valueObjinstanceofString[]){String[]values=(String[])valueObj;for(inti=0;i<values.length;i++){value=values[i]+",";}
3、value=value.substring(0,value.length()-1);}else{value=valueObj.toString();}returnMap.put(name,value);}map=returnMap;}publicPageData(){map=newHashMap();}
4、@OverridepublicObjectget(Objectkey){Objectobj=null;if(map.get(key)instanceofObject[]){Object[]arr=(Object[])map.get(key);obj=request==null?arr:(request.getParameter((String)key)==null?arr:arr[0]);}else{obj=map.get(key);}returnobj;}
5、publicStringget讵症慧鹱String(Objectkey){return(String)get(key);}@SuppressWarnings(&quo墉掠载牿t;unchecked")@OverridepublicObjectput(Objectkey,Objectvalue){returnmap.put(key,value);}@OverridepublicObjectremove(Objectkey){returnmap.remove(key);}publicvoidclear(){map.clear();}publicbooleancontainsKey(Objectkey){//TODOAuto-generatedmethodstubreturnmap.containsKey(key);}publicbooleancontainsValue(Objectvalue){//TODOAuto-generatedmethodstubreturnmap.containsValue(value);}publicSetentrySet(){//TODOAuto-generatedmethodstubreturnmap.entrySet();}publicbooleanisEmpty(){//TODOAuto-generatedmethodstubreturnmap.isEmpty();}publicSetkeySet(){//TODOAuto-generatedmethodstubreturnmap.keySet();}
6、@SuppressWarnings("unchecked")publicvoidputAll(Mapt){//TODOAuto-generatedmethodstubmap.putAll(t);}publicintsize(){//TODOAuto-generatedmethodstubreturnmap.size();}
7、publicCollectionvalues(){//TODOAuto-generatedmethodstubreturnmap.values();}}直接将上面的复制即可;解决