使用Struts2的iterator标签遍历复杂Map种类
2.创建两个实体类:
a). Mother(母亲)的Java类。
package struts.map.entity;
import java.io.Serializable;
public class Mother implements Serializable {
private static final long serialVersionUID = 1L;
private int motherId; //母亲ID
private String motherName; //母亲名字
public int getMotherId() {
return motherId;
}
public void setMotherId(int motherId) {
this.motherId = motherId;
}
public String getMotherName() {
return motherName;
}
public void setMotherName(String motherName) {
this.motherName = motherName;
}
}
b).Children(孩子)的Java类
import java.io.Serializable;
public class Children implements Serializable {
private static final long serialVersionUID = 1L;
private int childId; //孩子ID
private int motherId; //母亲的ID
private String childName; //孩子名字
public int getChildId() {
return childId;
}
public void setChildId(int childId) {
this.childId = childId;
}
public int getMotherId() {
return motherId;
}
public void setMotherId(int motherId) {
this.motherId = motherId;
}
public String getChildName() {
return childName;
}
public void setChildName(String childName) {
this.childName = childName;
}
}
3. 创建一个Action。并创建一位母亲和她的孩子。
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import struts.map.entity.Children;
import struts.map.entity.Mother;
import com.opensymphony.xwork2.ActionSupport;
public class Struts2_Map extends ActionSupport {
private static final long serialVersionUID = 1L;
private Map<Mother,List<Children>> motherChildn;
public Map<Mother, List<Children>> getMotherChildn() {
return motherChildn;
}
@Override
public String execute() throws Exception {
/*-------------------以对象做父节点的键,List做子节点的值。的Map-----------------------*/
Mother mother = new Mother();
mother.setMotherId(10000);
mother.setMotherName("花木兰");
Children children1 = new Children();
children1.setChildId(10000);
children1.setMotherId(10000);
children1.setChildName("小花木兰1");
Children children2 = new Children();
children2.setChildId(10001);
children2.setMotherId(10000);
children2.setChildName("小花木兰2");
Children children3 = new Children();
children3.setChildId(10002);
children3.setMotherId(10000);
children3.setChildName("小花木兰3");
motherChildn = new HashMap<Mother,List<Children>>();
List<Children> childrens = new ArrayList<Children>();
childrens.add(children1);
childrens.add(children2);
childrens.add(children3);
motherChildn.put(mother,childrens);
return SUCCESS;
}
}
struts.xml
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd">
<struts>
<package name="map" extends="struts-default">
<action name="struts_map" class="struts.map.test.Struts2_Map">
<result>result.jsp</result>
</action>
</package>
</struts>
4.创建两个页面:
a).跳转页面:
<%
String path = request.getContextPath();
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Struts_Map</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
</head>
<body>
<a href="struts_map.action">查看Map</a>
</body>
</html>
b).终于页面,也是作重要的页面:
<%@taglib uri="/struts-tags" prefix="s" %>
<%
String path = request.getContextPath();
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Struts_Map</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
</head>
<body>
<div>
<h3>-----------------以对象做父节点的键,List做子节点的值。的Map--------------------</h3>
<s:iterator var="mc" value="motherChildn">
<div>
母亲名称:<s:property value="key.motherName"/>
</div>
<s:iterator var="ch" value="value">
<div>
孩子名称:<s:property value="#ch.childName"/>
</div>
</s:iterator>
</s:iterator>
</div>
</body>
</html>
终于执行结果:
版权声明:本文博客原创文章,博客,未经同意,不得转载。
使用Struts2的iterator标签遍历复杂Map种类的更多相关文章
- struts2使用iterator标签显示嵌套Map - 云自无心水自闲 - BlogJava
"> <s:iterator value="dataMap.keySet()" id="class"> ...
- 使用struts2的iterator标签出现的错误
错误如下所示: 代码如下所示: <body> <s:debug></s:debug> 获取list的值第一种方式 <!-- 3 获取值栈list集合数据 -- ...
- Struts2标签遍历List<Map<String,String>>
<s:if test="resultList != null && resultList.size() > 0"> <s:iterator ...
- c标签遍历List<Map<String, Object>> 数据格式
<c:forEach varStatus="loop" var="dataMap" items="${dataMap}"> &l ...
- 转:Struts2<s:iterator value="" var="lst">中var的使用和一些标签的使用体会
比如<s:iterator value="pmOperateList" var="lst"> <!-- iterator加上var 等价于重新 ...
- Struts 2的iterator标签来遍历一个含有双层List的嵌套
今天碰到一个很有意思的问题,就是需要用Struts 2的iterator标签来遍历一个含有双层List的嵌套. 首先我们从最基础的说起,用iterator标签遍历一个List. 如果Action中有一 ...
- struts2标签 遍历map集合
首先我们来构造几个map集合. 假设如下代码 都是在ssh配置环境下搭建好,(至少struts2开发环境搭建好) (1).java 代码 下面的student对象包含的字段为 ...
- struts2的s:iterator 标签 详解
s:iterator 标签有3个属性:value:被迭代的集合id :指定集合里面的元素的idstatus 迭代元素的索引1:jsp页面定义元素写法 数组或list <s:iterator ...
- struts2的s:iterator 标签 详解<转>
struts2的s:iterator 可以遍历 数据栈里面的任何数组,集合等等 以下几个简单的demo: s:iterator 标签有3个属性: value:被迭代的集合 id : ...
随机推荐
- System.ComponentModel.Win32Exception (0x80004005):拒绝访问。——解决办法
一.问题如下: (无法执行程序.所执行的命令为 "C:\Windows\Microsoft.NET\Framework64\v4.0.30319\csc.exe" /noconfi ...
- [TypeScript] Create random integers in a given range
Learn how to create random integers using JavaScript / TypeScript. /** * Returns a random int betwee ...
- [Angular Directive] 2. Add Inputs to Angular 2 Directives
The @Input decorator allows you to pass values into your @Directive so that you can change the value ...
- poi读取excell表格
原文链接:http://blog.csdn.net/qq_37936542/article/details/79024847 最近项目需要实现一个将excell中的数据导入数据库,在网上找到这篇文章, ...
- Hibernate之HQL检索(查询)方式
HQL(Hibernate Query Language)是面向对象的查询语言,与SQL非常相似.在Hibernate中,HQL是使用最广泛的检索方式. 具有下面经常使用功能: (1)在查询语句中,能 ...
- VC++ 訪问数据库实例具体解释图解
一 ADO 方式訪问 Access 新建一个对话框project,加入控件,如图: watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2 ...
- EM12C 安装及卸载 注意点整理
版本号: em12c 12.1.0.4 OS : redhat 5.7 x86_64bit (CentOS6.2,測试过,当时因glibc*.i686包安装一直报错.所以放弃了) ...
- JavaStuNote 4
装箱(inbox)和拆箱(outbox) 代表了类类型和基本类型之间的转换行为. 手动版本号: Integer b = new Integer(10); Int a = b.intValue; 自己主 ...
- CEO 系列之一:如何当好创业公司 CEO?(不要用战术的勤奋掩盖战略的懒惰,在创业过程中,最核心问题,就是能把创业情怀变成具体问题。这个问题越具体越好)
1. 创业公司要先定一个目标,要善于把目标简化, 分解成一个, 一个更具体,更简单的问题2. 针对简单的问题进行聚焦, 做深做强3. 在做的过程中, 把断地推出自己的产品到市场上去试错, 要用事实来证 ...
- log4j配置参考手册:log4j.properties和log4j.xml两种格式
log4j是Java Web开发中,最常用的日志组件之一.网上关于log4j的配置满天飞,我主要是从网上学习的配置.之前的很多年,主要使用log4j.properties这种格式.后来,项目中boss ...