beanwrapper设置和获取属性值

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
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值