我有一个在不同场景中具有完全不同参数的ParameterMap集
我需要的是ParameterMap
中的“键”字符串数组我最接近的是使用reportParams.toString(); 这是我以前得到的输出
ParameterMap reportParams = context.getRequestParameters();
System.out.println(reportParams.toString());
//输出
map ['username' - > 'user','decorate' - > '不','装饰' - > '空','ajax' - > 'true','_ eventId' - > 'refreshReport','VEFactorSelection' - > '1','campusAndFaculty' - > array ['111','113','115','118','112','114','116','117','21907','21908','99040','99010', '99100','99230','99240'],'_ flowExecutionKey' - > 'e4s1','reportLanguage' - > '3','日期' - > '2013/06/20','nameType2' - > '1','确认' - > '真']
所以我想要的最终结果是
username,decorate,decorator,ajax,_ecentId,VEFactorSelection,campusAndFaculty,_flowExecutionKey,reportLanguage,date,nameType2,confirm
我试过这个
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:无法转换属性类型'java.util.LinkedHashMap'的值为必需类型'org.hibernate.mapping.Map'的属性'readOnlyConfiguredExporters';嵌套异常是java.lang.IllegalStateException:无法将类型[java.util.LinkedHashMap]的值转换为属性“readOnlyConfiguredExporters”所需的类型[org.hibernate.mapping.Map]:找不到匹配的编辑器或转换策略
===============================一些额外的
以下是“ParameterMap”http://static.springsource.org/spring-webflow/docs/1.0.x/api/org/springframework/webflow/core/collection/ParameterMap.html
的API答案 0 :(得分:1)
这样做
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
编辑回答。试试这个
答案 1 :(得分:0)
你试过了吗?
ParameterMap reportParams = context.getRequestParameters();
Set<String> keys = reportParams.asMap().keySet();