简体   繁体   English

遍历 HashMap <string, arraylist<string> &gt; 使用 Struts 2</string,>

[英]Iterate over an HashMap<String, ArrayList<String>> with Struts 2

I am currently facing some difficulties with Struts2 and the s:iterate tag.我目前在使用 Struts2 和 s:iterate 标签时遇到了一些困难。

I want to display a label, which is the key in the HashMap, followed by a table (the value in the HashMap) containing every elements in the ArrayList, for each elements in the HashMap. I want to display a label, which is the key in the HashMap, followed by a table (the value in the HashMap) containing every elements in the ArrayList, for each elements in the HashMap.

For example,例如,

     label
  ----------
  | test1  |
  ----------
  | test2  |
  ----------



    label2
  ----------
  | test1  |
  ----------
  | test2  |
  ----------

I saw a lot of example for an HashMap but didn't find one for my case.我看到了很多 HashMap 的示例,但没有找到适合我的案例。

How can I do this?我怎样才能做到这一点?

Thanks,谢谢,

<s:iterator value="map">
  <h3><s:property value="key" /></h3>
  <table>
  <s:iterator value="value">
    <tr><td><s:property /></td></tr>
  </s:iterator>
  </table>
</s:iterator>

The iterator of a map is Map.Entry which gets put on the value stack and has two accessors, getKey() and getValue(). map 的迭代器是 Map.Entry,它被放入值堆栈并具有两个访问器 getKey() 和 getValue()。 Iterate over Entry printing the key, then iterate over the values printing the value.遍历打印键的条目,然后遍历打印值的值。 (The list item gets put on top of the value stack so s:property just prints the top.) (列表项被放在值堆栈的顶部,因此 s:property 只打印顶部。)

Map<String,List<String>> mapVo=new  HashMap<String,List<String>>();
<s:iterator value="mapVo"  var="mapList" status="status">
 <table>
    <s:property value="#status.index"></s:property>
   <s:property value="key"></s:property>
   <s:iterator  value="mapList" var="item" status="rowstatus">
     <tr>
       item
     </tr>
   </s:iterator>
 </table>
</s:iterator>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM