JSEL2.0支持嵌套访问,也就是dot操作符来访问变量里的属性例子

如何进行变量的访问支持嵌套访问,也就是dot操作符来访问变量里的属性,假设我们有一个Foo类:
定义foo类

public class foo {
private int age;
private int sexy;
private String brithday;
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public String getBrithday() {
return brithday;
}
public void setBrithday(String brithday) {
this.brithday = brithday;
}
public int getSexy() {
return sexy;
}
public void setSexy(int sexy) {
this.sexy = sexy;
}

}
定义调用方法

public void testClass() {
Expression el = factory.create(" foo.age + 2 * foo.sexy + obj.testAdd(1,2)");
foo f= new foo();
f.setAge(15);
f.setSexy(2);
HashMap<String, Object> context = new HashMap<String, Object>();
context.put("foo", f);
context.put("obj", this);
Object result22 = el.evaluate(context);
System.out.println("result22:"+result22);
}

public static void main(String[] args) {
JSELTest test = new JSELTest();
test.testClass();
}

运行结果:
result22:22
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值