Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/371.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 是否存在BeanUtils.populate的递归版本?_Java_Apache Commons - Fatal编程技术网

Java 是否存在BeanUtils.populate的递归版本?

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

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,它也会填充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);