簡體   English   中英

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

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

我目前在使用 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.

例如,

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



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

我看到了很多 HashMap 的示例,但沒有找到適合我的案例。

我怎樣才能做到這一點?

謝謝,

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

map 的迭代器是 Map.Entry,它被放入值堆棧並具有兩個訪問器 getKey() 和 getValue()。 遍歷打印鍵的條目,然后遍歷打印值的值。 (列表項被放在值堆棧的頂部,因此 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