java - 使用 s 解析 Struts2 标签中 Hashmap 的 ArrayList :iterator

标签 java arraylist struts2 hashmap dynamic-arrays

我有一个包含 HashMapArrayList,我正在尝试迭代 HashMapArrayList使用 Struts s:iterator 标记。我可以毫无问题地遍历 List ,但无法让它遍历 map 的条目。到目前为止我已经得到了这个:

import com.opensymphony.xwork2.ActionSupport;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class mapTest extends ActionSupport {
    public List<Map> listmap;

    public String execute() {
        listmapObject = new ArrayList();
        Map map = new HashMap();
        map.put("stationId", "alpha");
        map.put("stationName", "USA");
        map.put("CustomerName", "charlie"); 
        Map map2 = new HashMap();
        map2.put("stationId", "Beta");
        map2.put("stationName", "UK");
        map2.put("CustomerName", "johnny");
        listmapObject.add(map);
        listmapObject.add(map2);
        return SUCCESS;
    }
}

我需要像下面使用 struts s:iterator 等效的 Java 代码的结果

<table>         
    <thead>
        <th> <Station id> </th>
        <th> station Name </th>
        <th> Name </th>         
    </thead>
    <s:iterator value="listmapObject">
    <tr>
        <td> ((HashMap) listmapObject.get(i)).get("stationId") </td> 
        <td> ((HashMap) listmapObject.get(i)).get("stationName") </td>
        <td> ((HashMap) listmapObject.get(i)).get("CustomerName") </td>
    </tr>
    </s:iterator> 
</table>

感谢大家对我的帮助

最佳答案

我对Struts的JSP组件不是很熟悉,但我认为以下应该可行:

 <s:iterator value="listmapObject">
     <tr>
         <td><s:property value="[0]['stationId']" /></td>
         <td><s:property value="[0]['stationName']" /></td>
         <td><s:property value="[0]['CustomerName']" /></td>
     </tr>
 </s:iterator>

根据documentation[0] 表示列表项,因此在本例中是您的 HashMap

关于java - 使用 s 解析 Struts2 标签中 Hashmap 的 ArrayList :iterator,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29329355/

相关文章:

Java:在 ActionListener 中使用图形组件

java - 制作/实现数组列表的迭代器 - Java

java - 查找 ArrayList 对象 - 搜索不起作用?

file-upload - Struts 2 文件上传拦截器配置问题

java - 如何使用 Struts 2 验证 HTML 标签

Java 泛型 - 命名实际类型的实际类型

java - Netty 中的两种方式的 SSL 身份验证

java - SFTP Spring 集成的文件轮询和过滤问题

java - 将多个文本字段放入一个数组列表中

java - jquery 中 .post 的多次使用