public void beanWrapperTest(){
//Company下包含string companyname,List<Person>personList,Stud stud;
//Person下包含string personname,stud下包含string studnm;
//setValue
BeanWrapper company = new BeanWrapperImpl(new Company());
company.setPropertyValue("companyname","hw");
Beanwrapper stud = new BeanWrapperImpl(new Stud());
stud.setPropertyValue("studnm","456");
company.setPropertyvalue("stud",stud.getwrappedInstance());
Beanwrapper personl = new BeanwrapperImpl(new Person());
person1.setPropertyValue("personname","zhangsan");
BeanWrapper person2 = new BeanWrapperImpl (new Person());
person2.setPropertyvalue("personname","lisi");
//只能设置list的数组长度为1,personList的值是person2的值(person2覆盖了person1)
//company.setPropertyvalue("personList",person1.getWrappedInstance());
//company.setPropertyValue("personList",person2.getwrappedInstance());
//company.setPropertyValue("personList[0].personname","zhangsan1");
//设置company对象下的list数组personList的值
MutablePropertyValues persons = new MutablePropertyValues();
persons.add("personList[0]",person1.getWrappedInstance());
persons.add("personList[1]",person2.getwrappedInstance());
company.setPropertyValues(persons)
//getValue
string companyname=(string)company.getpropertyvalue("companyname");//hw
string studnm=(string)company.getPropertyvalue("stud.studnm");//456
Stud stud1 = (stud) company. getPropertyValue("stud");
//getArrayValue
List<Person> Listperson = (List) company . getPropertyValue ("personList");// size为2
string personname = (string) company.getPropertyValue("personList[1].personname");//lisi
}
beanwrapper设置和获取属性值
于 2021-04-09 08:42:49 首次发布