zoukankan      html  css  js  c++  java
  • 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);
    
        }
    }

    以上

  • 相关阅读:
    输入输出重定向
    MarkdownPad 2中编辑
    (转)Maven最佳实践:划分模块
    (转)maven设置内存
    我收集的sonar参考资料
    (转)linux service理解
    制作service服务,shell脚本小例子(来自网络)
    6
    4
    5
  • 原文地址:https://www.cnblogs.com/gmq-sh/p/5019993.html
Copyright © 2011-2022 走看看