Java 是否存在BeanUtils.populate的递归版本?
org.apache.commons.beanutils.beanutils:Java 是否存在BeanUtils.populate的递归版本?,java,apache-commons,Java,Apache Commons,org.apache.commons.beanutils.beanutils: BeanUtils.populate(Object bean, Map<String,? extends Object> properties); Populate the JavaBeans properties of the specified bean, based on the specified name/value pairs. 所以,在Person上调用populate,它也会填充addr
BeanUtils.populate(Object bean, Map<String,? extends Object> properties);
Populate the JavaBeans properties of the specified bean, based on the specified name/value pairs.
所以,在Person上调用populate,它也会填充address(假设address有一个默认构造函数)。您可以使用点(.)来完成此操作。如果要设置street-inside-address对象,请指定属性名称,如
address.street
eg
Map<String, String> propertyMap = new HashMap<String, String>();
propertyMap.put("name", "James Bond");
propertyMap.put("address.street", "London");
propertyMap.put("address.number", "007");
BeanUtilsBean.getInstance().populate(bean, propertyMap);
MapPropertyMap=newHashMap();
不动产映射put(“名称”、“詹姆斯·邦德”);
物业映射出售(“地址、街道”、“伦敦”);
物业映射put(“地址编号”、“007”);
BeanUtilsBean.getInstance().populate(bean,propertyMap);
只有当bean.address!=无效的也就是说,BeanUtilsBean.populate()不实例化地址。那么列表呢?
Map<String, String> propertyMap = new HashMap<String, String>();
propertyMap.put("name", "James Bond");
propertyMap.put("address.street", "London");
propertyMap.put("address.number", "007");
BeanUtilsBean.getInstance().populate(bean, propertyMap);