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("[email protected]"); 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(); } } }
时间: 2024-11-03 21:41:49