遍历 HashMap<String, ArrayList<String>&am

Iterate over an HashMaplt;String, ArrayListlt;Stringgt;gt; with Struts 2(遍历 HashMaplt;String, ArrayListlt;Stringgt;gt;使用 Struts 2)
本文介绍了遍历 HashMap<String, ArrayList<String>>使用 Struts 2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我目前在使用 Struts2 和 s:iterate 标签时遇到了一些困难.

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

我想显示一个标签,它是 HashMap 中的键,然后是一个包含 ArrayList 中每个元素的表(HashMap 中的值),用于 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 的迭代器是 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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

How to send data to COM PORT using JAVA?(如何使用 JAVA 向 COM PORT 发送数据?)
How to make a report page direction to change to quot;rtlquot;?(如何使报表页面方向更改为“rtl?)
Use cyrillic .properties file in eclipse project(在 Eclipse 项目中使用西里尔文 .properties 文件)
Is there any way to detect an RTL language in Java?(有没有办法在 Java 中检测 RTL 语言?)
How to load resource bundle messages from DB in Java?(如何在 Java 中从 DB 加载资源包消息?)
How do I change the default locale settings in Java to make them consistent?(如何更改 Java 中的默认语言环境设置以使其保持一致?)