我有一个ParameterMap集合,在不同的场景下有完全不同的参数
我需要的是 ParameterMap 中的“键”字符串数组
我得到的最接近的是使用reportParams.toString(); 这是我用来获得以下输出的内容
ParameterMap reportParams = context.getRequestParameters();
System.out.println(reportParams.toString());
//输出
map['用户名' -> '用户', '装饰' -> '无', '装饰器' -> '空', 'ajax' -> 'true', '_eventId' -> 'refreshReport', 'VEFactorSelection'-> '1', 'campusAndFaculty' -> 数组['111', '113', '115', '118', '112', '114', '116', '117', '21907 ', '21908', '99040', '99010', '99100', '99230', '99240'], '_flowExecutionKey' -> 'e4s1', 'reportLanguage' -> '3', '日期' -> '2013/06/20', 'nameType2' -> '1', '确认' -> 'true']
所以我想要的最终结果是
用户名、装饰、装饰器、ajax、_ecentId、VEFactorSelection、campusAndFaculty、_flowExecutionKey、reportLanguage、日期、nameType2、确认
我已经尝试过
ParameterMap reportParams = context.getRequestParameters();
final List<String> names = new ArrayList<String>();
for (final Object o: reportParams.asMap().keySet())
names.add((String) o);
final String[] array = names.toArray(new String[names.size()]);
System.out.println(array[0]); // this part is just to see if i get output
上述代码的最终结果:
====================================== org.springframework.beans.ConversionNotSupportedException:无法转换属性将属性“readOnlyConfiguredExporters”的类型“java.util.LinkedHashMap”的值设置为所需类型“org.hibernate.mapping.Map”;嵌套异常是 java.lang.IllegalStateException:无法将属性“readOnlyConfiguredExporters”的类型 [java.util.LinkedHashMap] 的值转换为所需类型 [org.hibernate.mapping.Map]:找不到匹配的编辑器或转换策略
==================================一些额外的
这是“ParameterMap”的 API http://static.springsource.org/spring-webflow/docs/1.0.x/api/org/springframework/webflow/core/collection/ParameterMap.html
最佳答案
这样就可以了
Map<String, String> result = new LinkedHashMap<String, String>(parameterMap.size());
for (Map.Entry<String, String[]> entry : parameterMap.entrySet()) {
if (entry.getValue().length > 0) {
result.put(entry.getKey(), entry.getValue()[0]);
}
}
Set<String> nameSet = result.keySet();
String[] namesHolder= new String[nameSet.size()];
nameSet.toArray(namesHolder);
你有它在namesHolder
已编辑答案。试试这个
关于java - 如何获取 ParameterMap 中的键值列表(Spring),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17228989/