话不多说!先总结:
1、字段相同,类型不同(不复制,也不报错)
2、子类父类
(1)子类传给父类(可以正常复制)
(2)父类传给子类(可以正常复制)
3、子类父类(属性类对象)
(1)子类属性传给父类属性(可以正常复制)
(2)父类属性传给子类属性(不复制,也不报错)
具体代码如下:
1、字段相同,类型不同(不复制,也不报错)
java"> RequestVO order = new RequestVO();order.setLinkId("linkId");order.setPayType("1");RequestVO2 order1 = new RequestVO2();BeanUtils.copyProperties(order, order1);System.out.println(order1.getLinkId());System.out.println(order1.getPayType());
java">linkId
null
2、子类父类
(1)子类传给父类(可以正常复制)
java"> RequestVTest order1 = new RequestVTest();order1.setLinkId("linkId1");order1.setOrderId("orderId1");order1.setPayType("payType");RequestVO order = new RequestVO();BeanUtils.copyProperties(order1, order);System.out.println(order.getLinkId());System.out.println(order.getPayType());
java">linkId1
payType
(2)父类传给子类(可以正常复制)
java"> OneToManyOrderRequestVTest order1 = new RequestVTest();RequestVO order = new RequestVO();order.setLinkId("linkId1");order.setOrderId("orderId1");BeanUtils.copyProperties(order, order1);System.out.println(order1.getLinkId());System.out.println(order1.getOrderId());
java">linkId1
orderId1
3、子类父类(属性类对象)
(1)子类属性传给父类属性(可以正常复制)
java"> UserRequestVO vo = new UserRequestVO();UserRequestVO2 vo1 = new UserRequestVO2();RequestVTest order1 = new RequestVTest();order1.setLinkId("linkId1");order1.setOrderId("orderId1");vo1.setOrderRequestVO(order1);BeanUtils.copyProperties(vo1, vo);System.out.println(vo.getOrderRequestVO().getLinkId());System.out.println(vo.getOrderRequestVO().getOrderId());
java">linkId1
orderId1
(2)父类属性传给子类属性(不复制,也不报错)
java"> UserRequestVO vo = new UserRequestVO();OrderRequestVO order1 = new OrderRequestVO();order1.setLinkId("linkId1");order1.setOrderId("orderId1");vo.setOrderRequestVO(order1);UserRequestVO2 vo1 = new UserRequestVO2();vo1.setOrderRequestVO(new OrderRequestVTest());BeanUtils.copyProperties(vo, vo1);System.out.println(vo1.getOrderRequestVO().getLinkId());System.out.println(vo1.getOrderRequestVO().getOrderId());
java">null
null