养生 装修 购物 美食 感冒 便秘 营销 加盟 小吃 火锅 管理 创业 搭配 减肥 培训 旅游

request.getParameterMap()问题

时间:2024-11-01 12:28:44

[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="";

request.getParameterMap()问题

request.getParameterMap()问题

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]+",";}

request.getParameterMap()问题

3、value=value.substring(0,value.length()-1);}else{value=valueObj.toString();}returnMap.put(name,value);}map=returnMap;}publicPageData(){map=newHashMap();}

request.getParameterMap()问题

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;}

request.getParameterMap()问题

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();}

request.getParameterMap()问题

6、@SuppressWarnings("unchecked")publicvoidputAll(Mapt){//TODOAuto-generatedmethodstubmap.putAll(t);}publicintsize(){//TODOAuto-generatedmethodstubreturnmap.size();}

request.getParameterMap()问题

7、publicCollectionvalues(){//TODOAuto-generatedmethodstubreturnmap.values();}}直接将上面的复制即可;解决

request.getParameterMap()问题

© 一点知识