BeanUtils.copyProperties(obj2,obj1);
把obj1 的属性值 复制给 obj2
import java.lang.reflect.InvocationTargetException;
import org.apache.commons.beanutils.BeanUtils;
public class CopyTest {
public static void main(String[] args) throws IllegalAccessException, InvocationTargetException {
Book book1 = new Book("summer come",20);
Book book2 = new Book();
BeanUtils.copyProperties(book2,book1);
System.out.println("book1:"+book1);;
System.out.println("book2:"+book2);;
}
}
控制台:
book1:Book [name=summer come, price=20]
book2:Book [name=summer come, price=20]