0

我有两个 pojo 类,它们包含相同的字段 private String nameId;

我的 dozermapping.xml 文件包含

<mappings xmlns="http://dozer.sourceforge.net"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://dozer.sourceforge.net                               http://dozer.sourceforge.net/schema/beanmapping.xsd">
      <mapping map-id="a"> 
    <class-a>com.ihx.util.Fileobject</class-a>
    <class-b>com.ihx.model.Test</class-b>   
    <field>
    <a>nameId</a>
    <b>nameId</b>
    </field> 
  </mapping>  
  </mappings>

我收到一个错误,如下所示

org.dozer.MappingException Property 'nameId' not found in Class: class java.lang.String`

我的代码包含包含

 List myMappingFiles = new ArrayList();
                 myMappingFiles.add("dozerMapping.xml");
                // myMappingFiles.add("someOtherDozerBeanMappings.xml");
                 DozerBeanMapper mapper = new DozerBeanMapper();
                 mapper.setMappingFiles(myMappingFiles);
                 String p="com.ihx.util.Fileobject";
                 String p1="com.ihx.model.Test";
                 mapper.map(p, p1, "a");
4

1 回答 1

0
List myMappingFiles = new ArrayList();
myMappingFiles.add("dozerMapping.xml");
// myMappingFiles.add("someOtherDozerBeanMappings.xml");
DozerBeanMapper mapper = new DozerBeanMapper();
mapper.setMappingFiles(myMappingFiles);
com.ihx.util.Fileobject p= new Fileobject();
p.setNameId("testNameId");
com.ihx.model.Test p1 = new com.ihx.model.Test();
mapper.map(p, p1, "a");
String mappedNameId = p1.getNameId();
// This mappedNameId should now be the testNameId we set earlier. 

p 和 p1 需要是要转换的实际类对象,其中包含数据。p1 然后从 p 获取映射到它的数据。

于 2014-01-03T12:24:03.547 回答