Chinaunix首页 | 论坛 | 博客
  • 博客访问: 587060
  • 博文数量: 68
  • 博客积分: 5070
  • 博客等级: 大校
  • 技术积分: 1312
  • 用 户 组: 普通用户
  • 注册时间: 2007-10-11 14:20
文章分类

全部博文(68)

文章存档

2011年(3)

2010年(30)

2009年(17)

2008年(18)

我的朋友

分类: 系统运维

2010-05-24 21:38:40

  1. package com.zx.demo.action;   
  2.   
  3. import java.util.ArrayList;   
  4. import java.util.HashMap;   
  5. import java.util.List;   
  6. import java.util.Map;   
  7.   
  8. import com.opensymphony.xwork2.ActionSupport;   
  9. import com.zx.demo.model.Product;   
  10. import com.zx.demo.model.Student;   
  11.   
  12. public class MapAction extends ActionSupport   
  13. {   
  14.   
  15.     private Map map;   
  16.       
  17.     private Map studentMap;   
  18.        
  19.     private Map arrayMap;   
  20.        
  21.     private Map> listMap;   
  22.        
  23.   
  24.   
  25.     public String testMap()   
  26.      {   
  27.          map=new HashMap();   
  28.          map.put("1", "one");   
  29.          map.put("2", "two");   
  30.            
  31.          studentMap=new HashMap();   
  32.          studentMap.put("student1",new Student(new Long(1),"20034140201","张三1","男",25));   
  33.          studentMap.put("student2",new Student(new Long(2),"20034140202","张三2","女",26));   
  34.          studentMap.put("student3",new Student(new Long(3),"20034140202","张三3","男",27));   
  35.            
  36.          arrayMap=new HashMap();   
  37.          arrayMap.put("arr1", new String[]{"1","2003401","leejie","male","20"});   
  38.          arrayMap.put("arr2", new String[]{"2","2003402","huanglie","male","25"});   
  39.          arrayMap.put("arr3", new String[]{"3","2003403","lixiaoning","male","21"});   
  40.            
  41.            
  42.            
  43.          listMap=new HashMap>();   
  44.            
  45.          List list1=new ArrayList();   
  46.          list1.add(new Student(new Long(1),"20034140201","张三1","男",25));   
  47.          list1.add(new Student(new Long(2),"20034140202","张三2","男",25));   
  48.          list1.add(new Student(new Long(3),"20034140203","张三3","男",25));   
  49.          listMap.put("class1", list1);   
  50.            
  51.          List list2=new ArrayList();   
  52.          list2.add(new Student(new Long(1),"20034140301","李四1","男",20));   
  53.          list2.add(new Student(new Long(2),"20034140302","李四2","男",21));   
  54.          list2.add(new Student(new Long(3),"20034140303","李四3","男",22));   
  55.          list2.add(new Student(new Long(4),"20034140304","李四4","男",23));   
  56.          listMap.put("class2", list2);   
  57.             
  58.            
  59.            
  60.            
  61.         return SUCCESS;   
  62.            
  63.      }   
  64.   
  65.        
  66.        
  67.     public Map getMap() {   
  68.         return map;   
  69.      }   
  70.   
  71.     public void setMap(Map map) {   
  72.         this.map = map;   
  73.      }   
  74.        
  75.     public Map getStudentMap() {   
  76.         return studentMap;   
  77.      }   
  78.   
  79.     public void setStudentMap(Map studentMap) {   
  80.         this.studentMap = studentMap;   
  81.      }   
  82.   
  83.   
  84.     public Map getArrayMap() {   
  85.         return arrayMap;   
  86.      }   
  87.   
  88.   
  89.     public void setArrayMap(Map arrayMap) {   
  90.         this.arrayMap = arrayMap;   
  91.      }   
  92.   
  93.   
  94.   
  95.     public Map> getListMap() {   
  96.         return listMap;   
  97.      }   
  98.   
  99.   
  100.   
  101.     public void setListMap(Map> listMap) {   
  102.         this.listMap = listMap;   
  103.      }   
  104.        
  105.        
  106. }  


2.testMap.jsp
Java代码 复制代码
  1. <%@ page contentType="text/html;charset=UTF-8" %>   
  2. <%@ taglib prefix="s" uri="/struts-tags" %>   
  3.   
  4.   
  5. struts2中的map遍历总结   
  6.   
  7.   
  8.     1.map中的value为String字符串
      
  9.     "map" id="column">   
  10.     "#column"/>
      
  11.     key: "key"/>
      
  12.     value:"value"/>
      
  13.     ******************************************
      
  14.      
  15.   
  16.   
  17.    2.map中的value为Student对象   
  18.    "1" width="50%"   cellspacing="0" cellpadding="0">   
  19.     
  20.   
  21.       
  22.   
  23.       
  24.   
  25.       
  26.   
  27.       
  28.   
  29.       
  30.   
  31.       
  32.   
  33.     
  34.   
  35.      "studentMap" id="column">   
  36.     
  37.   
  38.      
  39.   
  40.      
  41.   
  42.      
  43.   
  44.      
  45.   
  46.      
  47.   
  48.      
  49.   
  50.     
  51.   
  52.        
  53.   
  54. key=value ID num name sex age
    "#column"/> "value.id"/> "value.num"/> "value.name"/> "value.sex"/> "value.age"/>
      
  55.   

      

  56.      
  57.      
  58.    3.map中的value为String数组   
  59.    "1" width="50%"   cellspacing="0" cellpadding="0">   
  60.     
  61.   
  62.       
  63.   
  64.       
  65.   
  66.       
  67.   
  68.       
  69.   
  70.       
  71.   
  72.       
  73.   
  74.     
  75.   
  76.      "arrayMap" id="column">   
  77.     
  78.   
  79.      
  80.   
  81.      
  82.   
  83.      
  84.   
  85.      
  86.   
  87.      
  88.   
  89.      
  90.   
  91.     
  92.   
  93.        
  94.   
  95. key=value ID num name sex age
    "#column"/> "value[0]"/> "value[1]"/> "value[2]"/> "value[3]"/> "value[4]"/>
      
  96.   

      

  97.    4.map中的value为list集合   
  98.    "1" width="50%"   cellspacing="0" cellpadding="0">   
  99.     
  100.   
  101.       
  102.   
  103.       
  104.   
  105.       
  106.   
  107.       
  108.   
  109.       
  110.   
  111.       
  112.   
  113.     
  114.   
  115.        
  116.     "listMap" id="column">   
  117.       "total" value="#column.value.size"/>   
  118.       "#column.value" status="s">   
  119.       
  120.   
  121.          if test="#s.first">
  122. if>   
  123.         
  124.   
  125.         
  126.   
  127.         
  128.   
  129.         
  130.   
  131.         
  132.   
  133.       
  134.   
  135.         
  136.      
  137. class ID num name sex age
    "${total}">"#column.key"/> "id"/> "num"/> "name"/> "sex"/> "age"/>
      
  138.      
  139.      
  140.   
  141.   
阅读(8547) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~