使用Ognl需要导入两个包:
测试小程序:
package helloWorld;
import ognl.Ognl;
import ognl.OgnlException;
public class TestOgnl {
public static void main(String[] args) {
Person person=new Person();
person.setName("Abby");
try {
Object value=Ognl.getValue("name",person);
System.out.println(value);
} catch (OgnlException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
class Person{
String name="";
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
/////////输出Abby
时间: 2024-12-23 21:23:43