dozer

Posted tonggc1668

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了dozer相关的知识,希望对你有一定的参考价值。

applicationContext.xml

    <bean id="mapper" class="org.dozer.spring.DozerBeanMapperFactoryBean" scope="singleton">
        <property name="mappingFiles">
            <list>
                <value>classpath*:/*mapping.xml</value>
            </list>
        </property>
    </bean>

pom.xml

      <!-- dozer -->
    <dependency>
        <groupId>net.sf.dozer</groupId>
        <artifactId>dozer</artifactId>
                <version>5.5.1</version>
    </dependency>
    
    <dependency>
        <groupId>net.sf.dozer</groupId>
        <artifactId>dozer-spring</artifactId>
        <version>5.5.1</version>
    </dependency>

outboundnotice-mapping.xml

<?xml version="1.0" encoding="UTF-8"?>
<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 wildcard="false" type="one-way">
        <class-a>com.yundaex.wms.outbound.po.RivOutboundNoticeH</class-a>
        <class-b>com.yundaex.wms.core.status.po.RivStatusHistory</class-b>
        
        <!-- 单头ID -->
        <field>
            <a>onhId</a>
            <b>shHeaderId</b>
        </field>
        
    </mapping>
    
    <mapping wildcard="false" type="one-way">
        <class-a>com.yundaex.wms.outbound.po.RivPickL</class-a>
        <class-b>com.yundaex.wms.core.status.po.RivStatusHistory</class-b>
        
        <!-- 单头ID -->
        <field>
            <a>pklId</a>
            <b>shHeaderId</b>
        </field>
        
    </mapping>
        
    <mapping type="one-way" wildcard="false">
        <class-a>com.yundaex.wms.outbound.bo.SrcPickAllocateBO</class-a>
        <class-b>com.yundaex.wms.core.store.bo.QuantWithDtl</class-b>
        
        <field>
            <a>detail.pklSrcContainerId</a>
            <b>qtContainerId</b>
        </field>
        
        <field>
            <a>detail.pklExpiryDate</a>
            <b>qtExpiryDate</b>
        </field>
        
        <field>
            <a>detail.pklSrcLocationId</a>
            <b>qtLocationId</b>
        </field>
        
        <field>
            <a>detail.pklLotItem1</a>
            <b>qtLotItem1</b>
        </field>        
        
        <field>
            <a>detail.pklLotItem2</a>
            <b>qtLotItem2</b>
        </field>
        
        <field>
            <a>detail.pklLotItem3</a>
            <b>qtLotItem3</b>
        </field>
        
        <field>
            <a>detail.pklLotNo</a>
            <b>qtLotNo</b>
        </field>
        
        <field>
            <a>detail.pklLotString1</a>
            <b>qtLotString1</b>
        </field>
        
        <field>
            <a>detail.pklLotString2</a>
            <b>qtLotString2</b>
        </field>
        
        <field>
            <a>detail.pklLotString3</a>
            <b>qtLotString3</b>
        </field>
        
        <field>
            <a>detail.pklLotString4</a>
            <b>qtLotString4</b>
        </field>
        
        <field>
            <a>detail.pklLotString5</a>
            <b>qtLotString5</b>
        </field>
        
        <field>
            <a>detail.pklSrcLpn</a>
            <b>qtLpn</b>
        </field>
        
        <field>
            <a>detail.pklManufDate</a>
            <b>qtManufDate</b>
        </field>
        
        <field>
            <a>detail.pklMaterialId</a>
            <b>qtMaterialId</b>
        </field>
        
        <field>
            <a>detail.pklMaterialStatusId</a>
            <b>qtMaterialStatusId</b>
        </field>
        
        <field>
            <a>head.onhOrgId</a>
            <b>qtOrgId</b>
        </field>
        
        <field>
            <a>head.onhOwnerId</a>
            <b>qtOwnerId</b>
        </field>
        
        <field>
            <a>detail.pklRecvDate</a>
            <b>qtRecvDate</b>
        </field>
        
        <!--  推车格子号不作用于库存变动 拣货明细中格子号是一直为空的 -->
        <!-- 
        <field>
            <a>detail.pklSrcTrolleyCellNo</a>
            <b>qtTrolleyCellNo</b>
        </field>
        -->
        
        <field>
            <a>detail.pklVoucherNo</a>
            <b>qtVoucherNo</b>
        </field>
        
    </mapping>
    
    <mapping type="one-way" wildcard="false">
        <class-a>com.yundaex.wms.outbound.bo.DestPickAllocateBO</class-a>
        <class-b>com.yundaex.wms.core.store.bo.QuantWithDtl</class-b>
        
        <field>
            <a>detail.pklDestContainerId</a>
            <b>qtContainerId</b>
        </field>
        
        <field>
            <a>detail.pklExpiryDate</a>
            <b>qtExpiryDate</b>
        </field>
        
        <field>
            <a>detail.pklDestLocationId</a>
            <b>qtLocationId</b>
        </field>
        
        <field>
            <a>detail.pklLotItem1</a>
            <b>qtLotItem1</b>
        </field>        
        
        <field>
            <a>detail.pklLotItem2</a>
            <b>qtLotItem2</b>
        </field>
        
        <field>
            <a>detail.pklLotItem3</a>
            <b>qtLotItem3</b>
        </field>
        
        <field>
            <a>detail.pklLotNo</a>
            <b>qtLotNo</b>
        </field>
        
        <field>
            <a>detail.pklLotString1</a>
            <b>qtLotString1</b>
        </field>
        
        <field>
            <a>detail.pklLotString2</a>
            <b>qtLotString2</b>
        </field>
        
        <field>
            <a>detail.pklLotString3</a>
            <b>qtLotString3</b>
        </field>
        
        <field>
            <a>detail.pklLotString4</a>
            <b>qtLotString4</b>
        </field>
        
        <field>
            <a>detail.pklLotString5</a>
            <b>qtLotString5</b>
        </field>
        
        <field>
            <a>detail.pklDestLpn</a>
            <b>qtLpn</b>
        </field>
        
        <field>
            <a>detail.pklManufDate</a>
            <b>qtManufDate</b>
        </field>
        
        <field>
            <a>detail.pklMaterialId</a>
            <b>qtMaterialId</b>
        </field>
        
        <field>
            <a>detail.pklMaterialStatusId</a>
            <b>qtMaterialStatusId</b>
        </field>
        
        <field>
            <a>head.onhOrgId</a>
            <b>qtOrgId</b>
        </field>
        
        <field>
            <a>head.onhOwnerId</a>
            <b>qtOwnerId</b>
        </field>
        
        <field>
            <a>detail.pklRecvDate</a>
            <b>qtRecvDate</b>
        </field>
        
        <!--  推车格子号不作用于库存变动 拣货明细中格子号是一直为空的 -->
        <!-- 
        <field>
            <a>detail.pklSrcTrolleyCellNo</a>
            <b>qtTrolleyCellNo</b>
        </field>
        -->
        
        <field>
            <a>detail.pklVoucherNo</a>
            <b>qtVoucherNo</b>
        </field>
        
    </mapping>
    
    <mapping wildcard="false" type="one-way">
        <class-a>com.yundaex.wms.outbound.po.RivOutboundNoticeH</class-a>
        <class-b>com.yundaex.wms.outbound.po.RivOutboundNoticeH</class-b>
        
        <field>
            <a>onhCarrierId</a>
            <b>onhCarrierId</b>
        </field>
        
        <field>
            <a>onhConsignee</a>
            <b>onhConsignee</b>
        </field>
        
        <field>
            <a>onhConsigneeAddress</a>
            <b>onhConsigneeAddress</b>
        </field>
        
        <field>
            <a>onhConsigneeMobile</a>
            <b>onhConsigneeMobile</b>
        </field>
        
        <field>
            <a>onhConsigneePostCode</a>
            <b>onhConsigneePostCode</b>
        </field>
        
        <field>
            <a>onhConsigneeTel</a>
            <b>onhConsigneeTel</b>
        </field>
        
        <field>
            <a>onhExpectDatetime</a>
            <b>onhExpectDatetime</b>
        </field>
        
        <field>
            <a>onhInputDatetime</a>
            <b>onhInputDatetime</b>
        </field>
        
        <field>
            <a>onhInputUserId</a>
            <b>onhInputUserId</b>
        </field>
        
        <field>
            <a>onhOrderDatetime</a>
            <b>onhOrderDatetime</b>
        </field>
        
        <field>
            <a>onhOrgId</a>
            <b>onhOrgId</b>
        </field>
        
        <field>
            <a>onhOwnerId</a>
            <b>onhOwnerId</b>
        </field>
        
        <field>
            <a>onhTxType</a>
            <b>onhTxType</b>
        </field>
        
        <field>
            <a>onhConsAddressCity</a>
            <b>onhConsAddressCity</b>
        </field>
        
        <field>
            <a>onhConsAddressDistrict</a>
            <b>onhConsAddressDistrict</b>
        </field>
        
        <field>
            <a>onhConsAddressProvince</a>
            <b>onhConsAddressProvince</b>
        </field>
        
        <field>
            <a>onhShopName</a>
            <b>onhShopName</b>
        </field>
        
        <field>
            <a>onhPlatformCode</a>
            <b>onhPlatformCode</b>
        </field>
        
        <field>
            <a>onhPlatformName</a>
            <b>onhPlatformName</b>
        </field>
        
        <field>
            <a>onhBuyerNickname</a>
            <b>onhBuyerNickname</b>
        </field>
        
        <field>
            <a>onhTransactionNo</a>
            <b>onhTransactionNo</b>
        </field>
        
        <field>
            <a>onhPickUpType</a>
            <b>onhPickUpType</b>
        </field>
        
        <field>
            <a>onhSender</a>
            <b>onhSender</b>
        </field>
        
        <field>
            <a>onhSenderAddress</a>
            <b>onhSenderAddress</b>
        </field>
        
        <field>
            <a>onhSenderMobile</a>
            <b>onhSenderMobile</b>
        </field>
        
        <field>
            <a>onhSenderPostCode</a>
            <b>onhSenderPostCode</b>
        </field>
        
        <field>
            <a>onhSenderTel</a>
            <b>onhSenderTel</b>
        </field>
        
        <field>
            <a>onhSetPackageDestination</a>
            <b>onhSetPackageDestination</b>
        </field>
        
    </mapping>
    
    <mapping wildcard="false" type="one-way">
        <class-a>com.yundaex.wms.outbound.po.RivOutboundNoticeL</class-a>
        <class-b>com.yundaex.wms.outbound.po.RivOutboundNoticeL</class-b>
        
        <field>
            <a>onlMaterialId</a>
            <b>onlMaterialId</b>
        </field>
        
        <field>
            <a>onlPrice</a>
            <b>onlPrice</b>
        </field>
        
        <field>
            <a>onlNoticeQty</a>
            <b>onlNoticeQty</b>
        </field>
        
        <field>
            <a>onlAllocQty</a>
            <b>onlAllocQty</b>
        </field>
        
        <field>
            <a>onlRemark</a>
            <b>onlRemark</b>
        </field>
        
    </mapping>
    
</mappings>
private static final Mapper mapper = (Mapper) SpringContext.getBean("mapper");


QuantWithDtl sourceQuant = mapper.map(source, QuantWithDtl.class);

 

以上是关于dozer的主要内容,如果未能解决你的问题,请参考以下文章

dozer 简单用法

Dozer:如何限制映射的深度?

利用Dozer实现vo-Entiy-Model中属性的复用

用dozer实现两对象之间的复制

dozer

JavaBean递归拷贝工具类Dozer