2014-07-22 4 views
3

org.apache.commons.beanutils.BeanUtils :BeanUtils.populate의 재귀 버전이 있습니까?

BeanUtils.populate(Object bean, Map<String,? extends Object> properties); 
Populate the JavaBeans properties of the specified bean, based on the specified name/value pairs. 

BeanUtils.populate의 재귀 버전이 있습니까?

class Person { 
    String name; 
    Address address; 
} 
class Address { 
    String street; 
    int number 
} 

Person에서 전화를 걸면 주소에 기본 생성자가 있다고 가정하여 Person을 채 웁니다.

답변

0

도트 (.)를 사용하여이 작업을 수행 할 수 있습니다. 주소 내부 객체를 설정하려면 address.street과 같은 속성 이름을 지정하십시오. 예 :

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); 
+0

bean.address! = null 인 경우에만 작동합니다. 즉, BeanUtilsBean.populate()는 Address를 인스턴스화하지 않습니다. –

+1

목록은 어떻습니까

? – arisalexis

관련 문제