Skip to content

zhouhailin/common-bean

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

38 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

common-bean

Gitter
Jdk Version Build Status Coverage Status
Maven Central GitHub release License

版本迭代

  • fastjson实现 - 0.1.x
  • 注解实现 - 0.2.x
  • 反射实现 - 0.3.x
  • 动态代理实现 0.4.x

快速使用

  • java version
java version "1.8.0_181"
Java(TM) SE Runtime Environment (build 1.8.0_181-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.181-b13, mixed mode)
  • maven

<dependency>
  <groupId>link.thingscloud</groupId>
  <artifactId>common-bean</artifactId>
  <version>${common-bean.version}</version>
</dependency>
  • example
BeanCopier<BeanObject1, BeanObject2> beanCopier = BeanCopier.create(BeanObject1.class, BeanObject2.class,
            BeanCopierOptions.defaultOptions()
                    .ignoreFields("short2"));

    BeanObject1 beanObject1 = new BeanObject1()
            .setStr1("str1").setStr2("str2")
            .setShort1((short) 1).setShort2((short) 2)
            .setLong1(1L).setLong2(2L)
            .setDouble1(1D).setDouble2(2D)
            .setDate1(new Date(System.currentTimeMillis())).setDate2(new Date(System.currentTimeMillis()));

    @Test
    public void copy() {
        BeanObject1 copy = beanCopier.copy(beanObject1);
        System.out.println(copy);
    }

    @Test
    public void copy1() {
        BeanObject2 copy1 = beanCopier.copy(beanObject1, new BeanObject2());
        System.out.println(copy1);
    }
  • source & target object
@Data
@Accessors(chain = true)
public class BeanObject1 {
    private String str1;
    private String str2;
    private Short short1;
    private Short short2;
    private Long long1;
    private Long long2;
    private Date date1;
    private Date date2;
    private Double double1;
    private Double double2;
}

@Data
@Accessors(chain = true)
public class BeanObject1 {
    private String str1;
    private String str2;
    private Short short1;
    private Short short2;
    private Long long1;
    private Long long2;
    private Date date1;
    private Date date2;
    private Double double1;
    private Double double2;
}

License

Apache License, Version 2.0 Copyright (C) Apache Software Foundation