BeanUtils.copyProperties("要转换的类(source)", "转换后的类(target)"); 将user和userInfo拥有相同字段的值复制到userInfo对象中(如果user和userInfo间存在名称不相同的属性,则BeanUtils不对这些属性进行处理,需要手动处理)
import org.springframework.beans.BeanUtils
BeanUtils.copyProperties(user,userInfo);
另一个PropertyUtils.copyProperties()
PropertyUtils.copyProperties()方法几乎与BeanUtils.copyProperties()相同,主要的区别在于PropertyUtils.copyProperties()提供类型转换功能,即发现两个JavaBean的同名属性为不同类型时,在支持的数据类型范围内进行转换,BeanUtils不支持这个功能,所以说BeanUtils速度会更快一些,使用更普遍一点,犯错的风险更低一点。