码迷,mamicode.com
首页 > 编程语言 > 详细

java 对象之间的复制

时间:2016-07-06 13:12:48      阅读:169      评论:0      收藏:0      [点我收藏+]

标签:

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();
           }
        }
    }


 
 

 

java 对象之间的复制

标签:

原文地址:http://www.cnblogs.com/yy123/p/5646393.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!