大家好,欢迎来到IT知识分享网。
对象之间的转换;
深度复制;
1,BeanMap 实现的是Map接口;将对象转换成Map非常简单;
2,BeanCopier 深度复制;
Demo主要类:
Test:
/** * Created by admin on 2017/3/7. */
public class Test {
public static void main(String[] args) {
Test test = new Test();
User user = new User();
user.setAge(20);
user.setName("hengai");
BeanMap beanMap = BeanMap.create(user);
System.out.println(beanMap.get("age")+","+beanMap.get("name"));
Persion persion = new Persion();
BeanCopier beanCopier = BeanCopier.create(User.class,Persion.class,false);
beanCopier.copy(user,persion,null);
System.out.println(persion.toString());
}
}
User
/** * Created by admin on 2017/3/7. */
public class User {
private String name;
private int age;
public User(){
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
}
Persion:
/** * Created by admin on 2017/3/7. */
public class Persion {
private String name;
@Override
public String toString() {
return "Person [name=" + name + ", age=" + age + "]";
}
private int age;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
}
免责声明:本站所有文章内容,图片,视频等均是来源于用户投稿和互联网及文摘转载整编而成,不代表本站观点,不承担相关法律责任。其著作权各归其原作者或其出版社所有。如发现本站有涉嫌抄袭侵权/违法违规的内容,侵犯到您的权益,请在线联系站长,一经查实,本站将立刻删除。 本文来自网络,若有侵权,请联系删除,如若转载,请注明出处:https://yundeesoft.com/11942.html