使用orika实现对象间的拷贝
示例
UserIdPo.java
public class UserIdPo {
private String id;
// setter getter
}
UserEntity.java
public class UserEntity {
private String id;
private String name;
private Integer age;
// setter getter
}
BeanCopyTest.java
public class BeanCopyTest {
public static void main(String[] args) {
ma.glasnost.orika.impl.ConfigurableMapper mapper = new ma.glasnost.orika.impl.ConfigurableMapper();
UserIdPo po = new UserIdPo();
po.setId("userid");
UserEntity userEntity = mapper.map(po, UserEntity.class);
System.out.println(userEntity);
UserEntity userEntity2 = new UserEntity();
userEntity2.setAge(12);
userEntity2.setId("222");
userEntity2.setName("e2");
UserIdPo po2 = mapper.map(userEntity2, UserIdPo.class);
System.out.println(po2);
}
}