使用OGNL可以做到这一点。
class Mobile {
Manufacturer manufacturer;
String name;
String version;
// Getters and Setters
}
class Manufacturer {
String manuId;
String manuName;
// Getters and Setters
}
class MainClass {
public static void main(String[] args){
Mobile nexus6 = new Mobile();
Ognl.setValue("manufacturer.manuName", nexus6, "Motorola");
}
}
Ognl可以只实例化内部bean(制造商)并设置属性吗?