這篇文章給大家介紹怎么在Struts2中利用OGNL表達式對map進行遍歷,內(nèi)容非常詳細,感興趣的小伙伴們可以參考借鑒,希望對大家能有所幫助。
一.Action中的代碼:MapAction.java
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; //這里省略get set方法 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; } }
分享題目:怎么在Struts2中利用OGNL表達式對map進行遍歷-創(chuàng)新互聯(lián)
文章地址:http://aaarwkj.com/article40/dohieo.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站導(dǎo)航、全網(wǎng)營銷推廣、品牌網(wǎng)站設(shè)計、移動網(wǎng)站建設(shè)、微信公眾號、標簽優(yōu)化
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容