Struts标签<s:iterator>遍历访问复杂Map对象
<s:iterator value="resultType" id="geneUi"> //拿到要遍历的Map对象
<s:iterator value="#geneUi.value" id="typeMap"> //取得Map对象里代表value值的嵌套Map对象
<tr>
<s:iterator value="#typeMap.value" id="typeB"> //取得嵌套的Map对象中代表value值的List对象
<td><s:property value="#typeMap.key"/></td> //取得嵌套Map对象中遍历的每个元素的key值
<td><s:property value="#typeMap.value.size"/></td> //取得List对象的大小
<td><s:property value="typeB"/></td> //取得List对象的每个元素值
</s:iterator>
</tr>
</s:iterator>
</s:iterator> 其中第一个iterator的value值resultType为下面action中的成员变量 public class ***Action extends SupportAction {
private Map<String, Map<String, List<String>>> resultType = new HashMap<String, Map<String,List<String>>>(); ..........
.........
}
package com.zx.demo.action; import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map; import com.opensymphony.xwork2.ActionSupport;
import com.zx.demo.model.Product;
import com.zx.demo.model.Student; public class MapAction extends ActionSupport
{ private Map<String,String> map; private Map<String,Student> studentMap; private Map<String,String[]> arrayMap; private Map<String,List<Student>> listMap; public String testMap()
{
map=new HashMap<String,String>();
map.put("1", "one");
map.put("2", "two"); studentMap=new HashMap<String,Student>();
studentMap.put("student1",new Student(new Long(1),"20034140201","张三1","男",25));
studentMap.put("student2",new Student(new Long(2),"20034140202","张三2","女",26));
studentMap.put("student3",new Student(new Long(3),"20034140202","张三3","男",27)); arrayMap=new HashMap<String,String[]>();
arrayMap.put("arr1", new String[]{"1","2003401","leejie","male","20"});
arrayMap.put("arr2", new String[]{"2","2003402","huanglie","male","25"});
arrayMap.put("arr3", new String[]{"3","2003403","lixiaoning","male","21"}); listMap=new HashMap<String,List<Student>>(); List<Student> list1=new ArrayList<Student>();
list1.add(new Student(new Long(1),"20034140201","张三1","男",25));
list1.add(new Student(new Long(2),"20034140202","张三2","男",25));
list1.add(new Student(new Long(3),"20034140203","张三3","男",25));
listMap.put("class1", list1); List<Student> list2=new ArrayList<Student>();
list2.add(new Student(new Long(1),"20034140301","李四1","男",20));
list2.add(new Student(new Long(2),"20034140302","李四2","男",21));
list2.add(new Student(new Long(3),"20034140303","李四3","男",22));
list2.add(new Student(new Long(4),"20034140304","李四4","男",23));
listMap.put("class2", list2); return SUCCESS; } public Map<String, String> getMap() {
return map;
} public void setMap(Map<String, String> map) {
this.map = map;
} public Map<String, Student> getStudentMap() {
return studentMap;
} public void setStudentMap(Map<String, Student> studentMap) {
this.studentMap = studentMap;
} public Map<String, String[]> getArrayMap() {
return arrayMap;
} public void setArrayMap(Map<String, String[]> arrayMap) {
this.arrayMap = arrayMap;
} public Map<String, List<Student>> getListMap() {
return listMap;
} public void setListMap(Map<String, List<Student>> listMap) {
this.listMap = listMap;
} }
<%@ page contentType="text/html;charset=UTF-8" %>
<%@ taglib prefix="s" uri="/struts-tags" %>
<html>
<head>
<title>struts2中的map遍历总结</title>
</head>
<body>
<b>1.map中的value为String字符串</b><br>
<s:iterator value="map" id="column">
<s:property value="#column"/><br>
key: <s:property value="key"/><br>
value:<s:property value="value"/><br>
******************************************<br>
</s:iterator> <b>2.map中的value为Student对象</b>
<table border="1" width="50%" cellspacing="0" cellpadding="0">
<tr>
<td>key=value</td>
<td>ID</td>
<td>num</td>
<td>name</td>
<td>sex</td>
<td>age</td>
</tr>
<s:iterator value="studentMap" id="column">
<tr>
<td><s:property value="#column"/></td>
<td><s:property value="value.id"/></td>
<td><s:property value="value.num"/></td>
<td><s:property value="value.name"/></td>
<td><s:property value="value.sex"/></td>
<td><s:property value="value.age"/></td>
</tr>
</s:iterator>
</table>
<p> <b>3.map中的value为String数组</b>
<table border="1" width="50%" cellspacing="0" cellpadding="0">
<tr>
<td>key=value</td>
<td>ID</td>
<td>num</td>
<td>name</td>
<td>sex</td>
<td>age</td>
</tr>
<s:iterator value="arrayMap" id="column">
<tr>
<td><s:property value="#column"/></td>
<td><s:property value="value[0]"/></td>
<td><s:property value="value[1]"/></td>
<td><s:property value="value[2]"/></td>
<td><s:property value="value[3]"/></td>
<td><s:property value="value[4]"/></td>
</tr>
</s:iterator>
</table>
<p>
<b>4.map中的value为list集合</b>
<table border="1" width="50%" cellspacing="0" cellpadding="0">
<tr>
<td>class</td>
<td>ID</td>
<td>num</td>
<td>name</td>
<td>sex</td>
<td>age</td>
</tr> <s:iterator value="listMap" id="column">
<s:set name="total" value="#column.value.size"/>
<s:iterator value="#column.value" status="s">
<tr>
<s:if test="#s.first"><td rowspan="${total}"><s:property value="#column.key"/></td></s:if>
<td><s:property value="id"/></td>
<td><s:property value="num"/></td>
<td><s:property value="name"/></td>
<td><s:property value="sex"/></td>
<td><s:property value="age"/></td>
</tr>
</s:iterator>
</s:iterator>
</table> </body>
</html>
Struts标签<s:iterator>遍历访问复杂Map对象的更多相关文章
- Struts 2的iterator标签来遍历一个含有双层List的嵌套
今天碰到一个很有意思的问题,就是需要用Struts 2的iterator标签来遍历一个含有双层List的嵌套. 首先我们从最基础的说起,用iterator标签遍历一个List. 如果Action中有一 ...
- Play Framework常用标签list,set,如何遍历list、map类型数据
最近一段时间的项目都是在Play这个框架上进行开发的,挺强大的,但不足之处也挺多的.今天分享下play中强大的标签,遍历list,map类型的数据的用法. 遍历单纯的list数据,例如:List< ...
- Java SE之For增强与Iterator遍历器提取数据(附Map.Entry)
增强for循环: 1.操作数组 2.操作List集合 3.操作Map集合 1.map.values()法 2.map.keySet()法 [传统方法] 3.Map.Entry法 ...
- struts 标签库注解
在struts2中有着一套像html一样的标签,俗称struts2标签,大多数公司使用ssh都是使用html标签,但为了保持项目的统一性,有的公司还是使用的struts2的标签,下面是一些常用的str ...
- Struts标签、Ognl表达式、el表达式、jstl标签库这四者之间的关系和各自作用
我之前虽然会用,但是一直分不清彼此之间有什么区别,所以查找资料,将它们进行整合区分,加深了解, 一 介绍 1.Struts2的作用 Struts2标签库提供了主题.模板支持,极大地简化了视图页面的 ...
- JSTL、EL、ONGL、Struts标签的区别与使用
一.JSTL 来源 我们使用JSP开发信息展现非常方便,也可嵌入java代码用来实现相关逻辑,但同样带来了很多问题: jsp维护难度增加 出事提示不明确,不容易提示 分工不明确等 解决上面的问题可以 ...
- Struts标签库详解【3】
struts2标签库详解 要在jsp中使用Struts2的标志,先要指明标志的引入.通过jsp的代码的顶部加入以下的代码: <%@taglib prefix="s" uri= ...
- Struts标签库详解【1】
struts2标签详解 要在jsp中使用Struts2的标志,先要指明标志的引入.通过jsp的代码的顶部加入以下的代码: <%@taglib prefix="s" uri=& ...
- ongl与Struts标签
一.ONGL OGNL 的全称是“Object-Graph Navigation Language”,即对象图导航语言,它是一种功能强大的开源表达式语言.使用这种表达式语言可以通过某种表达式语法存取 ...
随机推荐
- PHP源码阅读笔记一(explode和implode函数分析)
PHP源码阅读笔记一一.explode和implode函数array explode ( string separator, string string [, int limit] )此函数返回由字符 ...
- Install SharePoint 2013 on Windows Server 2012 without a domain
Any setup of Team Foundation Server is not complete until you have at least tried t work with ShareP ...
- my9.23(输入输出,写操作)
#include <iostream> #include <fstream> using namespace std; void write(int data,int len) ...
- 容斥原理算法总结(bzoj 2986 2839)
容斥原理是一个从小学就开始学习的算法.但是很多难题现在都觉得做的十分吃力. 容斥原理大概有两种表现形式,一种是按照倍数进行容斥,这个东西直接用莫比乌斯函数就可以了. #include<iostr ...
- [ecmall]Ecmall 后台添加模板编辑区
例如,想把品牌/index.php?app=brand页面做成可编辑的. 首先,找到后台admin\includes\menu.inc.php第61行 'template' => array( ...
- EasyUI datagrid数据表格的函数getData返回来的是什么
EasyUI datagrid数据表格的函数getData返回来的是什么? 他返回来的是这么一个对象: Object { rows=[10], total=15} 其中rows就是每一行的数据,是这些 ...
- 【网络流24题】 No.2 太空飞行计划问题 (最大闭合权图 最大流 )
原题: W教授正在为国家航天中心计划一系列的太空飞行.每次太空飞行可进行一系列商业性实验而获取利润.现已确定了一个可供选择的实验集合 E={E1,E2,...,Em},和进行这些实验需 ...
- HTML Jquery;marquee标签
在<网页制作Dreamweaver(悬浮动态分层导航)>中,运用到了jQuery的技术,轻松实现了菜单的下拉.显示.隐藏的效果,不必再用样式表一点点地修改,省去了很多麻烦,那么jQuery ...
- 机器学习10大经典算法.doc
详见 F:\工程硕士\d电子书\26 数据挖掘 小结: 1. C4.5 C4.5算法是机器学习算法中的一种分类决策树算法,其核心算法是ID3算法. C4.5算法继承了ID3算法的优点,并在以下几方面 ...
- linux 下 epoll 编程
转载自 Linux epoll模型 ,这篇文章讲的非常详细! 定义: epoll是Linux内核为处理大批句柄而作改进的poll,是Linux下多路复用IO接口select/poll的增强版本,它能显 ...