問(wèn)題描述
我目前在使用 Struts2 和 s:iterate 標(biāo)簽時(shí)遇到了一些困難.
I am currently facing some difficulties with Struts2 and the s:iterate tag.
我想顯示一個(gè)標(biāo)簽,它是 HashMap 中的鍵,然后是一個(gè)包含 ArrayList 中每個(gè)元素的表(HashMap 中的值),用于 HashMap 中的每個(gè)元素.
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 |
----------
我看到了很多關(guān)于 HashMap 的示例,但沒(méi)有找到適合我的案例.
I saw a lot of example for an HashMap but didn't find one for my case.
我該怎么做?
謝謝,
推薦答案
<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,它被放入值堆棧并具有兩個(gè)訪問(wèn)器,getKey() 和 getValue().遍歷打印鍵的條目,然后遍歷打印值的值.(列表項(xiàng)被放在值堆棧的頂部,因此 s:property 只打印頂部.)
The iterator of a map is Map.Entry which gets put on the value stack and has two accessors, getKey() and 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.)
這篇關(guān)于遍歷 HashMap<String, ArrayList<String>>使用 Struts 2的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!