spring的对象属性相同(类型,名字)拷贝
A类:
package test; /** * Created by gmq on 2015/12/4. */ public class A { private String aa; private Long bb; private Integer cc; public Integer getCc() { return cc; } public void setCc(Integer cc) { this.cc = cc; } public String getAa() { return aa; } public void setAa(String aa) { this.aa = aa; } public Long getBb() { return bb; } public void setBb(Long bb) { this.bb = bb; } }
B类:
package test; /** * Created by gmq on 2015/12/4. */ public class B { private String aa; private Long bb; private String cc; public String getAa() { return aa; } public void setAa(String aa) { this.aa = aa; } public Long getBb() { return bb; } public void setBb(Long bb) { this.bb = bb; } public String getCc() { return cc; } public void setCc(String cc) { this.cc = cc; } }
测试类:
package test; import com.banksteel.erp.dto.inventory.allot.InventoryItemDto; import com.banksteel.erp.inventory.entity.inventory.InventoryItem; import com.github.pagehelper.PageInfo; import org.springframework.beans.BeanUtils; import java.util.ArrayList; import java.util.List; /** * Created by gmq on 2015/12/4. */ public class TestUtil { public static void main(String args[]) { A a = new A(); a.setAa("test"); a.setBb(11L); a.setCc(2); B b = new B(); BeanUtils.copyProperties(a, b); System.out.println(a.getAa() + " " + a + " " + a.getBb() + ", c: " + a.getCc()); System.out.println(b.getAa() + " " + b + " " + b.getBb()+ ", c: " + b.getCc()); // InventoryItem item = new InventoryItem(); // item.setStatus(11); // item.setItemCode("gmq"); // // InventoryItemDto dto = new InventoryItemDto(); // BeanUtils.copyProperties(item, dto); // System.out.println(item.getStatus() + " " + " " + item.getItemCode()); // System.out.println(dto.getStatus() + " " + " " + dto.getItemCode()); // PageInfo<InventoryItemDto> dtoPage = new PageInfo<>(); // PageInfo<InventoryItem> itemPage = new PageInfo<>(); // List<InventoryItem> items = new ArrayList<>(); // InventoryItem item = new InventoryItem(); // item.setId(123L); // items.add(item); //// itemPage.setList(items); // itemPage.setList(null); // itemPage.setPageSize(100); // BeanUtils.copyProperties(itemPage, dtoPage); // System.err.println(dtoPage); } }
以上
弱水_穿云天