这两天做项目,用到了BeanUtils.copyProperties()这个方法,而在两个不同的类中使用到这个方法,但不知怎么的,copy属性总是出问题,最后排查终于找到原因。

BeanUtils.copyProperties(productInfo,orderDetail); //把属性拷贝过来

有两个类中包含有BeanUtils,且都有copyProperties方法,一个类为org.springframework.beans.BeanUtils,另一个是org.apache.commons.beanutils.BeanUtils,这两个类在不同的包下面,而这两个类的copyProperties()方法里面传递的参数赋值是相反的。

例如:

productInfoorderDetail为两对象

BeanUtils.copyProperties(productInfo,orderDetail);

BeanUtilsorg.springframework.beans.BeanUtils,则是将productInfo中的属性拷贝到orderDetail

BeanUtilsorg.apache.commons.beanutils.BeanUtils,则是将orderDetail中的属性拷贝到productInfo.

相关文章:

  • 2021-10-28
  • 2021-11-02
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-12-13
  • 2021-07-31
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-11
  • 2021-07-14
相关资源
相似解决方案