Struts-OGNL-3
来源:互联网 发布:mac os 10.12.6下载 编辑:程序博客网 时间:2024/06/16 19:01
JSP中
<%--注意该项在Struts2.5中不能生效,在struts2.1.6中可以 显示age=8--%><%--http://localhost:8080/hello/ognl/ognl 在User类中重写toString()即可--%><li>访问普通属性的构造方法:</li><s:property value="new dto.User(8)"></s:property><br><%--http://localhost:8080/hello/ognl/ognl--%><li>访问List:</li><s:property value="users"/><br/>访问List中某个元素:<s:property value="users[1]"/><br/>访问List中元素某个属性的集合:<s:property value="users.{age}"/><br/>访问List中元素某个属性的集合中的特定值:<s:property value="users.{age}[0]"/> | <s:property value="users[0].age"/><br/>访问Set:<s:property value="dogs"/><br/><%--set中是无顺序的,所以不能取到下标值--%>访问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}.{age}"></s:property><br/><%--^代表开头的那个 是2--%>投影:<s:property value="users.{^#this.age>1}.{age}"></s:property><br/><%--$代表结尾的那个 是2--%>投影:<s:property value="users.{$#this.age>1}.{age}"></s:property><br/>投影:<s:property value="users.{$#this.age>1}.{age}==null"></s:property><br/>投影:<s:property value="users.{$#this.age>1}.{age}.size"></s:property><br/><%--使用中括号访问元素 用于代表ValueStack中的Object对象--%><%--什么时候会存在多个action 当struts.xml中result使用type=chain跳转时 会存在多个action存入栈中--%><%--[0]代表从第0个位置一直向下找,所以会打印2个对象 []:[com.ognl.OgnlAction@4f046661, com.opensymphony.xwork2.DefaultTextProvider@b02d3a6]--%>[]:<s:property value="[0]"></s:property>
Action中
private List<User> users = new ArrayList<User>(); private Set<Dog> dogs = new HashSet<Dog>(); private Map<String, Dog> dogMap = new HashMap<String, Dog>(); public OgnlAction() { users.add(new User("1")); users.add(new User("2")); users.add(new User("3")); dogs.add(new Dog("dog1")); dogs.add(new Dog("dog2")); dogs.add(new Dog("dog3")); dogMap.put("dog100", new Dog("dog100")); dogMap.put("dog101", new Dog("dog101")); dogMap.put("dog102", new Dog("dog102")); }
效果:
0 0
- Struts-OGNL-3
- struts ognl
- Struts-OGNL
- 【xy】struts--OGNL、Struts-tags
- Struts 2中的OGNL
- Struts 2中的OGNL
- Struts 2中的OGNL
- Struts 2中的OGNL
- Struts 2中的OGNL
- Struts 2中的OGNL
- Struts 2中的OGNL
- Struts 2中的OGNL
- Struts 2中的OGNL
- Struts 2中的OGNL
- Struts 2中的OGNL
- Struts 2中的OGNL
- Struts 2中的OGNL
- Struts 2中的OGNL
- 各种坑的合集
- 异常处理
- 1017. A除以B (20)
- 网上图书商城视频教程day01
- xml文件的读写
- Struts-OGNL-3
- 分页实现
- JavaScript语言精粹(一)(词法作用域,JSON及其服务器处理,document.write()与document.writeln()区别)
- jquery eval解析JSON中的注意点介绍
- ECMAScript引用类型之Array类型
- Vue的列表的渲染
- MySQL中的触发器
- 为PhpStorm添加Laravel 代码智能提示功能
- JS瀑布流下拉加载数据效果