推土机将一个lavel类映射到具有嵌套类(例如字段)的类

时间:2018-06-29 12:41:55

标签: java dozer

我有课外课程

public class A{
    private String f1;
    private String f2;
    private String f3;
    private String f4;
  }

我有目标类B。B包含С类,例如field。

 public class B{
    private String f1;
    private String f2;
    private C c;
  }

  public class C{
    private String f3;
    private String f4;
  }

我需要将地图A映射到B。我创建了mapperBuilder和配置逻辑

BeanMappingBuilder mappingBuilder = new BeanMappingBuilder() {
    @Override
    protected void configure() {

      TypeMappingBuilder test = mapping(A.class, B.class);
      test .fields("f1", "f1");
      test .fields("f2", "f2");
      test .fields("f3", "???");
      test .fields("f4", "???");//How can I set f4 value to b.c.f4?
    }
  };

我创建了映射器:

  A a = new A();
  //add data to a object
  mapper = new DozerBeanMapper();
  mapper.addMapping(mappingBuilder);
  B b= mapper.map(a, B.class);

0 个答案:

没有答案