b2科目四模拟试题多少题驾考考爆了怎么补救
b2科目四模拟试题多少题 驾考考爆了怎么补救

ognl表达式#号_ognl表达式和el表达式_ognl表达式(3)

电脑杂谈  发布时间:2017-02-12 00:03:46  来源:网络整理

public class OGNLDemo3 {
	//测试赋值
	@Test
	public void testOGNL1() throws Exception{
		User user = new User();

		Ognl.setValue("username", user, "张三");
		System.out.println(user.getUsername());
	}

	@Test
	public void testOGNL2() throws Exception{
		User user = new User();

		Map context = new HashMap();
		context.put("u1", user);

		Ognl.setValue("#u1.username", context, new Object(), "张三");
		System.out.println(user.getUsername());
	}

	@Test
	public void testOGNL3() throws Exception{
		User user = new User();

		Map context = new HashMap();
		context.put("u1", user);

		//getValue也可以赋值:利用"="进行赋值
		String value = (String) Ognl.getValue("#u1.username='李四'", context, new Object());
		System.out.println(user.getUsername());
		System.out.println(value);
	}

	@Test
	public void testOGNL4() throws Exception{
		User user = new User();
		User user2 = new User();

		Map context = new HashMap();
		context.put("u1", user);
		context.put("u2", user2);

		//用逗号分隔,同时执行多个表达式
		String value = (String) Ognl.getValue("#u1.username='李四',#u2.username='王五'", context, new Object());
		System.out.println(user.getUsername());
		System.out.println(value);
	}
}

④ 使用OGNL调用对象中的方法


本文来自电脑杂谈,转载请注明本文网址:
http://www.pc-fly.com/a/jisuanjixue/article-31887-3.html

相关阅读
    发表评论  请自觉遵守互联网相关的政策法规,严禁发布、暴力、反动的言论

    热点图片
    拼命载入中...