Flask接口签名sign原理与实例代码浅析
447
2023-03-28
Struts2 使用OGNL遍历map方法详解
一.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
private Map
private Map
private Map
//这里省略get set方法
public String testMap(){
map=new HashMap
map.put("1", "one");
map.put("2", "two");
studentMap=new HashMap
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
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
List
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
list2.add(new Student(new Long(1),"2003http://4140301","李四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;
}
}
二.前端测试页面:testMap.jsp
Java代码
<%@ page
contentType="text/html;charset=UTF-8"
%>
<%@ taglib prefix="s"
uri="/struts-tags" %>
1.map中的key为String,value为String字符串
key:
value:
******************************************
******************************************
2.map中的key为String,value为Student对象
******************************************
3.map中的key为String,value为String数组
******************************************
4.map中的key为String,value为list集合
附:map的类型为Map
总结
以上就是本文关于Struts2 使用OGNL遍历map方法详解的全部内容,希望对大家有所帮助。有兴趣的朋友可以参阅:OGNL表达式基本语法与用法详解 Struts2 通过ognl表达式实现投影 Struts2 OGNL表达式实例详解等。感谢大家对本站的支持。
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
发表评论
暂时没有评论,来抢沙发吧~