简体   繁体   English

没有XML的推土机API日期映射配置

[英]Dozer API Date Mapping config without XML

Anyone know how to convert the following into the api call format for Dozer? 任何人都知道如何将以下内容转换为Dozer的api调用格式? The documentation on the Dozer mapping site is pretty slim when it comes to the java mappings. 在涉及Java映射时,Dozer映射站点上的文档非常简洁。

   <mappings>
  <configuration>
    <date-format>MM/dd/yyyy HH:mm</date-format>
  </configuration>

  <mapping wildcard="true">
    <class-a>org.dozer.vo.TestObject</class-a>
    <class-b>org.dozer.vo.TestObjectPrime</class-b>
    <field>
      <a>dateString</a>
      <b>dateObject</b>
    </field>
  </mapping>
  <mapping>
    <class-a>org.dozer.vo.SomeObject</class-a>
    <class-b>org.dozer.vo.SomeOtherObject</class-b>
    <field>
      <a>srcField</a>
      <b>destField</b>
    </field>
  </mapping>
</mappings>

As of version 5.5.1 of Dozer, API syntax cannot perform all mappings . 从Dozer 5.5.1版开始, API语法无法执行所有映射 The <configuration> element in your mapping can only be done with XML. 映射中的<configuration>元素只能使用XML完成。

If you can accept a version that bypasses the <configuration> limitation by adding some duplication, then the API mapping below should match your XML mapping: 如果您可以通过添加一些重复来接受绕过<configuration>限制的版本,那么下面的API映射应该与您的XML映射匹配:

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

        String dateFormat = "MM/dd/yyyy HH:mm";

        mapping(TestObject.class, TestObjectPrime.class,
                TypeMappingOptions.wildcard(true),
                TypeMappingOptions.dateFormat(dateFormat))
                .fields("dateString", "dateObject");

        mapping(SomeObject.class, SomeOtherObject.class,
                TypeMappingOptions.dateFormat(dateFormat))
                .fields("srcField", "destField");
    }
};

DozerBeanMapper apiBeanMapper = new DozerBeanMapper();
apiBeanMapper.addMapping(mappingBuilder);

If you're interested in further details, I've added a simple ApiAndXmlMappingTest example to PasteBin. 如果您对更多细节感兴趣,我已经向PasteBin添加了一个简单的ApiAndXmlMappingTest示例

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM