java 对象之间的复制

package com.jy.demo.web;

import java.util.Date;

public  class People {
    private String name;//姓名
    private int age;//年龄
    private String email;
    private Date date;

    public Date getDate() {
        return date;
    }
    public void setDate(Date date) {
        this.date = date;
    }
    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;
    }
    public String getEmail() {
        return email;
    }
    public void setEmail(String email) {
        this.email = email;
    }
   
}
package com.jy.demo.web;

import java.util.Date;

public  class Person {
    private String name;
    private int age;
    private String address;
    private Date date;
    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;
    }
    public String getAddress() {
        return address;
    }
    public void setAddress(String address) {
        this.address = address;
    }
    public Date getDate() {
        return date;
    }
    public void setDate(Date date) {
        this.date = date;
    }
   
}
package com.jy.demo.web;

import java.lang.reflect.InvocationTargetException;
import java.util.Date;

import org.apache.commons.beanutils.BeanUtils;

import com.alibaba.fastjson.JSON;

public class Test4 {
    public static void main(String[] args) {
           People tobby=new People();
           tobby.setAge(23);
           tobby.setName("CMTobby");
           tobby.setEmail("xiaozhu87487705@163.com");
           tobby.setDate( new Date());
           Person cindy=new Person();
           
            try {
                 BeanUtils.copyProperties(cindy, tobby);
               System.out.println(JSON.toJSON(cindy));
           } catch (IllegalAccessException e) {
               e.printStackTrace();
           } catch (InvocationTargetException e) {
               e.printStackTrace();
           }
        }
    }


 
 

 

posted @ 2016-07-06 11:40  也许还年轻  阅读(451)  评论(0编辑  收藏  举报