标签:
OGNL 对象图导航语言
Struts框架默认支持ognl表达式语言
作用-页面取值
ognl必须配合struts标签用
原理代码演示
@Test public void testOgnl() throws OgnlException { //创建一个ognl对象 OgnlContext context = new OgnlContext(); User user = new User(); user.setId("1"); user.setName("cx"); //设置根元素 context.setRoot(user); //context.put("user",user);
//Object ognl = Ognl.parseExpression("#user.name");
// 底层解析 Object ognl = Ognl.parseExpression("name"); //得到value Object value = Ognl.getValue(ognl,context,context.getRoot()); System.out.println(value); //context.put("cn","China"); //String value = (String) context.get("cn"); //System.out.println(value); }
标签:
原文地址:http://www.cnblogs.com/cxspace/p/5668458.html