struts2中ognl(Object Graph Navigation Laguage)的使用
一,访问普通的属性和方法
1,访问值栈中的action的普通属性值
<s:property value="name"/>
2,访问值栈中对象的普通属性(get set方法)
user.xxx只有传,才会构造,
想初始化domain model,
可以自己new,User=new User();Use u = new User(9);
也可以传参数值,?user.age=9
但这时候需要保持参数为空的构造方法public User(){......}
<s:propery value="user.age"/>
3,访问值栈中对象的普通方法 password.length()
4,访问值栈中对象的普通方法 cat.miaomaio()
5,访问值栈中action的普通方法 m()
二,访问静态的属性和方法
1,访问静态的属性
@类名.@属性
2,访问静态的方法
@类名.@方法名
3,访问Math类的静态方法:
<s:property value="@@max(2,3)" />
三,访问普通类的构造方法:
访问普通类的构造方法:<s:property value="new com.struts2.ognl.dao.User(8)"/>
四,访问集合类
访问List:<s:property value="users"/><br/>
访问List中某个元素:<s:property value="users[1]"/><br/>
访问List中元素某个属性的集合:<s:property value="users.{name}"/><br/>
访问List中元素某个属性的集合中的特定值:
<s:property value="users.{name}[0]"/> | <s:property value="users[0].name"/><br/>
访问Set:<s:property value="dogs"/><br/>
访问Set中某个元素:<s:property value="dogs[1]"/><br/>
访问Map:<s:property value="dogMap"/><br/>
访问Map中某个元素:<s:property value="dogMap.dog101"/> | <s:property value="dogMap['dog101']"/> | <s:property value="dogMap[\"dog101\"]"/><br/>
访问Map中所有的key:<s:property value="dogMap.keys"/><br/>
访问Map中所有的value:<s:property value="dogMap.values"/><br/>
访问容器的大小:<s:property value="dogMap.size()"/> | <s:property value="users.size"/> <br/>
五,投影(过滤)
投影(过滤):<s:property value="users.{?#this.age==1}[0]"/>
投影:<s:property value="users.{^#this.age>1}.{age}"/>
投影:<s:property value="users.{$#this.age>1}.{age}"/>
投影:<s:property value="users.{$#this.age>1}.{age} == null"/>
六,通过[]访问
[]:<s:property value="[0]"/><br/>
<s:property value="[0].user.name"/>
分享到:
相关推荐
struts2 中 OGNL表达式的使用struts2 中 OGNL表达式的使用
本实例:实现了用ongl取得servlet对象值;用ongl对集合中的对象进行筛选; 以及ongl表达式的显示生命
本资源适合刚接触Struts和Ognl的小伙伴交流学习,欢迎吐槽。
从官网checkout下来的源码,如果大家觉的区官网麻烦可以直接下载这个
Struts2学习计划5---Struts2_OGNL(对象图导航语言)的学习
Struts2中ognl-2的源代码,从官网下载的
Struts2 的OGNL使用简介实例 博文链接:https://zmx.iteye.com/blog/553748
struts2的ognl
struts2_ognl基本用法.docstruts2_ognl基本用法.docstruts2_ognl基本用法.docstruts2_ognl基本用法.docstruts2_ognl基本用法.docstruts2_ognl基本用法.docstruts2_ognl基本用法.docstruts2_ognl基本用法.docstruts2_...
关于struts2中ognl的说明、原理及使用,对于初学者进阶是个不错的参考
有对struts2标签和OGNL的总结。
struts2 OGNL,struts2 表达式语言,Struts2 中OGNL表达式的用法,Struts2 #,表达式语言的好处,Struts2 $,struts2 井号,星号,百分号
ognl与struts2_ognl
struts2-OGNL表达式测试代码
NULL 博文链接:https://xiangkw.iteye.com/blog/1103095
struts2和ognl的一些知识,struts2中文教程,中文帮助文档
struts2 OGNL的主要用法 基本覆盖全部
Struts2的一个关键特性就是它可以对Action携带的数据进行读写访问,例如在前面我们在表单中使用user.username指定数据传递给Action的user对象的username属性,在元素中使用user.username来获取用户的名字,这是通过...
NULL 博文链接:https://chaoyi.iteye.com/blog/2158731
java的Struts中的OGNL标签的使用,详细介绍,比较实用。