반응형

스프링 APA 하면서 Entity를 화면 전용 DTO 객체를 만들고 객체 변형하면서 삽질 하다가 발견한 유틸이다.


객체에 같은 프로퍼티의 값을 복사해준다.


BeanUtils.copyProperties(boardConfig, this);


void org.springframework.beans.BeanUtils.copyProperties(Object source, Object target) throws BeansException


Copy the property values of the given source bean into the target bean.

Note: The source and target classes do not have to match or even be derived from each other, as long as the properties match. Any bean properties that the source bean exposes but the target bean does not will silently be ignored.

This is just a convenience method. For more complex transfer needs, consider using a full BeanWrapper.

Parameters:
source the source bean
target the target bean
Throws:
BeansException - if the copying failed
See Also:
BeanWrapper


반응형

+ Recent posts