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

查看:137
本文介绍了迭代HashMap< String,ArrayList< String>>与Struts 2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前在Struts2和s:iterate标签方面遇到了一些困难。

I am currently facing some difficulties with Struts2 and the s:iterate tag.

我想显示一个标签,这是HashMap中的关键,然后是对于HashMap中的每个元素,包含ArrayList中每个元素的表(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.

例如,

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



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

我看了很多例子一个HashMap,但没有为我的案例找到一个。

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.Entry,它放在值堆栈上,有两个访问器, getKey()和getValue()。迭代条目打印键,然后迭代打印值的值。 (列表项放在值堆栈的顶部,所以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.)

这篇关于迭代HashMap&lt; String,ArrayList&lt; String&gt;&gt;与Struts 2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆