2013-07-02 4 views
3

봄의 BeanUtils.copyProperties() 특정 속성을 무시하는 옵션을 제공 무시하는 API : BeanUtils의 copyProperties 콩 복사하는 동안 널 특정 propertie

public static void copyProperties(Object source, 
       Object target, 
       String[] ignoreProperties) throws BeansException 

는 아파치 코 몬즈 BeanUtils 비슷한 기능을 제공 하는가를?

Date defaultValue = null; 
DateConverter converter = new DateConverter(defaultValue); 
ConvertUtils.register(converter, Date.class); 

내가 봄의 BeanUtils와 같은를 얻을 수 있습니다

또한 그것은 봄의 BeanUtils.copyProperties(), 나는 커먼즈 BeanUtils이 기능을보고 사용하는 동안 null 값을 무시할 수 있습니까?

답변

4

당신은 당신이 복사 등록하기 전에 다음의 코드와 함께 할 필요가 - 값 null를 무시하려면 다음 경우

BeanUtilsBean.getInstance().getConvertUtils().register(false, false, 0); 
+0

스 니펫은 무엇을 수행합니까? – kryger

+0

ConverterUtils가 이러한 등록 방법 (최소한 버전 1.7.0 이상)을 지원하지 않는 것 같습니다 – HieuHT

+0

아니요 ... 작동하지 않으며이 대답은 설명이 부족합니다. –

1

당신이이 org.springframework.beans.BeanUtils 당신이 방법 copyProperties(Object source, Object target, String... ignoreProperties)를 사용하여 특정 properies을 무시할 수 사용 . 예 :

BeanUtils.copyProperties(sourceObj, targetObj, "aProperty", "another");