org.apache.commons.beanutils.BeanUtils;
经测试为浅拷贝
public static void main(String[] args) { OrderCreatRespDTO orderCreatRespDTO = new OrderCreatRespDTO(); orderCreatRespDTO.setTakeAwayBillPayCreateDTO(new TakeAwayBillPayCreateDTO()); try { OrderCreatRespDTO o = (OrderCreatRespDTO) BeanUtils.cloneBean(orderCreatRespDTO); System.out.println(orderCreatRespDTO); System.out.println(o); System.out.println(orderCreatRespDTO.getTakeAwayBillPayCreateDTO()); System.out.println(o.getTakeAwayBillPayCreateDTO()); } catch (Exception e) { e.printStackTrace(); } }
结果:
mapstruct一样 浅拷贝
org.apache.commons.lang.SerializationUtils 深拷贝
json转换 深拷贝 效率比序列化高些
使用cglib.beans.BeanCopier 代理实现 传说效率更高之后研究。