Struts2创建项目4--ognl
来源:互联网 发布:利口酒 知乎 编辑:程序博客网 时间:2024/05/18 06:31
什么是ognl(Object Graphic Navgation Language)
对象图形导航语言, 通过一个图形,来完成和我们的对象的导航功能。
2、创建一个对象
package com.chb.struts2Test.model;/** * ognl Object graphic Navgation Language * 通过一个图形,来完成和我们对象进行导航的, * */public class User { private int id; private String username; private String nickname; public User(){} public User(int id, String username, String nickname) { super(); this.id = id; this.username = username; this.nickname = nickname; } public int getId() { return id; } public void setId(int id) { this.id = id; } public String getUsername() { return username; } public void setUsername(String username) { this.username = username; } public String getNickname() { return nickname; } public void setNickname(String nickname) { this.nickname = nickname; }}
3、测试
4、在添加一个对象, User可能属于某个部门
package com.chb.struts2Test.model;//在添加一个对象, User可能属于某个部门public class Department { private String dptName; public Department() { } public Department(String dptName) { super(); this.dptName = dptName; } public String getDptName() { return dptName; } public void setDptName(String dptName) { this.dptName = dptName; }}
在User中添加相应的属性
package com.chb.struts2Test.model;/** * ognl Object graphic Navgation Language * 通过一个图形,来完成和我们对象进行导航的, * */public class User { private int id; private String username; private String nickname; private Department dep; public User(){} public User(int id, String username, String nickname) { super(); this.id = id; this.username = username; this.nickname = nickname; } public Department getDep() { return dep; } public void setDep(Department dep) { this.dep = dep; } public int getId() { return id; } public void setId(int id) { this.id = id; } public String getUsername() { return username; } public void setUsername(String username) { this.username = username; } public String getNickname() { return nickname; } public void setNickname(String nickname) { this.nickname = nickname; }}
现在导航图增加属性
获取dep的属性值
二、如果我们需要多个根,将怎么做
2.1 使用一个map将多个根存入, 作为一个大的Context,#对象.属性
来获取属性值
Object ognl.Ognl.getValue(Object tree, Map context, Object root) throws OgnlExcption
getValue有三个参数,
Object tree: 寻找的值的表达式
Map context: context, 使用#对象.属性名来从contxt中寻找
Object root: 根, 默认在根中寻找对应的值
2.2如果使用list作为根, 如何查询
三、尼玛, ognl还可以调用方法
在User里添加两个方法
public int sum(int a, int b){ return a + b; } public String hello(String word) { return "hello " + word; }
阅读全文
0 0
- Struts2创建项目4--ognl
- struts2 OGNL (4)
- struts2 ognl
- struts2 OGNL # % $
- struts2 OGNL # % $
- struts2 OGNL
- OGNL struts2
- struts2 OGNL
- Struts2 OGNL
- struts2 OGNL # % $
- Struts2---->OGNL
- Struts2 OGNL
- struts2 OGNL
- Struts2-OGNL
- struts2 OGNL
- STRUTS2 OGNL
- struts2 OGNL # % $
- struts2 - OGNL
- USACO-2017-FEB-金组 Why Did the Cow Cross the Road
- MapReduce 分析 Youtube 数据
- minetest源码解析八:ClientEnvironment
- 打印长方框
- DOS短文件名规则
- Struts2创建项目4--ognl
- final修饰符 10条易错问题总结
- C语言MD5源码及实例
- SpringBoot学习笔记--HelloWorld
- java由长方形到三角形的输出推理
- 去哪儿笔试:filename extension
- [LeetCode]101. Symmetric Tree
- [py]三次退出+n退出+加法训练器
- MySQL中基本的多表连接查询教程