使用 s:iterator 解析 Struts2 标签中 Hashmap 的 ArrayList
Parsing ArrayList of Hashmap in Struts2 tag using s:iterator
我有一个包含 HashMap
的 ArrayList
,我正在尝试使用 Struts s:iterator
标签。我可以毫无问题地遍历 List
,但我无法让它遍历地图的条目。到目前为止,我得到了这个:
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;
}
}
我需要像下面这样的结果 Java 等效于使用 struts s:iterator
的代码
<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
.
我有一个包含 HashMap
的 ArrayList
,我正在尝试使用 Struts s:iterator
标签。我可以毫无问题地遍历 List
,但我无法让它遍历地图的条目。到目前为止,我得到了这个:
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;
}
}
我需要像下面这样的结果 Java 等效于使用 struts s:iterator
<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
.