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

spring的对象属性相同(类型,名字)拷贝

时间:2015-12-04 20:11:56      阅读:139      评论:0      收藏:0      [点我收藏+]

标签:

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

    }
}

以上

spring的对象属性相同(类型,名字)拷贝

标签:

原文地址:http://www.cnblogs.com/gmq-sh/p/5019993.html

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