使用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 : ...
随机推荐
- iis windows phpstudy安装redis扩展
说明,我的服务器是2008 64位 php5.4.33 首先下载符合条件的redis扩展,是否符合条件可以参考https://pecl.php.net/package/redis,进入之后,点击&qu ...
- HDU 1069 Monkey and Banana DP LIS
http://acm.hdu.edu.cn/showproblem.php?pid=1069 题目大意 一群研究员在研究猴子的智商(T T禽兽啊,欺负猴子!!!),他们决定在房顶放一串香蕉,并且给猴子 ...
- [Node.js] Use nodejs-dashboard event loop delay with hrtime()
In this lesson, you will learn how to use the Formidable nodejs-dashboard event loop delay to identi ...
- Android 闹钟最终版
以下是我发现的几点闹钟中重要的点,分享一下: (1)在闹钟中有AudioManager管理机制,这个机制可以申请和释放OnAudioFocusChangeListener监听. 还有mTelephon ...
- maven打包到本地库
mvn install:install-file -DgroupId=com.alipay -DartifactId=com.alipay.core -Dversion=20180104135026 ...
- C# 软件编码规范
一.代码注释 并不是所有的代码均需要注释. 1.类头部注释 /// <summary> /// 描述类的用途 /// 作者: 张三 /// 日期: 2015/12/1 /// </s ...
- javaScript_with用法
with语句用途 暂时改变作用域链.简化代码. 语法结构 with(object){ //其他语句 } 例1 with(person){ name= "zhang"; addres ...
- PHP移动互联网开发笔记(1)——环境搭建及配置
开篇说明:记得我上大二的时候第一次听到PHP,当时只知道这是一个开发网站的语言,并没有深入学习,在学了Java Web开发和Android开发之后我对互联网的发展方向有了一个我自己的认识,现在我们不能 ...
- $.ajax 请求 拦截器 重定向 无效 解决办法
在ajax 异步请求下 拦截器过滤器中使用 重定向 页面响应无效 我这里用的是springboot框架,用拦截器实现 对请求的拦截 ,session超时直接跳转到login.html页面. 后台代码: ...
- kettle的job中运行每行
job中运行每行 有时,我们须要job或转换执行多次.且每次传入的參数都不同.假如你正在做数据迁移的工作,须要导入每天的旧数据,则须要一个job依据指定的日期导入数据,该日期被指定作为參数.假设 ...