Copy specific fields by using BeanUtils.copyProperties?

前端 未结 5 1884
执笔经年
执笔经年 2020-12-12 14:13

springframework.beans.BeanUtils is very useful to copy objects, and I use the \"ignoreProperties\" option frequently. However, sometimes I want to copy only spe

5条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-12 14:42

    If you don't want to use Commons BeanUtils you can still use Spring by using the BeanWrapper.

    You will have to manually loop through all the properties so you will want to make a static helper method.

    You can always just copy what copyProperties is doing and adjust to your liking: http://tinyurl.com/BeanUtils-copyProperties

提交回复
热议问题