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);
时间: 2024-10-10 21:31:58

dozer的相关文章

Dozer 自定义Converter -- LocalDateTime to Date

Spring boot项目,使用dozer将Jpa Entity中的LocalDateTime属性转到DTO中对应的LocalDateTime属性中报错 java.lang.NoSuchMethodException: java.time.LocalDateTime.<init>() at java.lang.Class.getConstructor0(Class.java:3082) ~[na:1.8.0_51] at java.lang.Class.getDeclaredConstruct

对象的克隆,Dozer的使用

现在有个复杂对象bean需要在赋值后在另一个地方用,想通过复制的方式拿到这个对象.首选是深度克隆,虽然发现该对象的父类已经实现了Cloneable接口,但父类是通过jar包引入的,而且在clone方法中对该bean一个map<String, Object>属性的处理有问题:获取到map的value时,直接强制转型为某一具体bean,而子类这个map在put时并非该具体bean的类型,因此克隆时报转型失败错误.考虑方案二,通过java序列化方式克隆,父类也已经实现了Serializable接口,

dozer 简单用法

maven添加必要的库: 1 <!-- https://mvnrepository.com/artifact/net.sf.dozer/dozer --> 2 <dependency> 3 <groupId>net.sf.dozer</groupId> 4 <artifactId>dozer</artifactId> 5 <version>5.5.1</version> 6 </dependency>

Dozer 实现对象间属性复制

使用场景:两个领域之间对象转换. 比如:在系统分层解耦过程中, 对外facade接口,一般使用VO对象,而内core业务逻辑层或者数据层通常使用Entity实体. VO对象 package com.maven.demo; public class ProductVO{ private Long id; private String name; private String description; public Long getId() { return id; } public void se

一个强大易用的java bean之间属性复制框架--Dozer介绍

Dozer is a Java Bean to Java Bean mapper that recursively copies data from one object to another. Typically, these Java Beans will be of different complex types. 更多内容见:http://dozer.sourceforge.net/documentation/about.html 两个简单示例: map --> bean假设由reque

dozer学习笔记

简介 Dozer是一款javaBean的映射工具,用于解决一个类到另外一个类的自动适配功能,它即支持简单的映射,也支持复杂类型的双向递归映射(官网). 示例 举个例子,假设说我们现在有User(用户).UserDetail(用户详细)两个实体类,但对外公布时,我们发布了UserDto.UserSimpleDto两个传输对象,现在我们来实现他们之间的相互转化: 用户:记录登录名.密码 1 /** 2 * @author X 3 */ 4 public class User { 5 6 privat

dozer使用中发现的一个问题

源对象中有一个orderId属性, 目的对象继承了源对象, 当用dozer从源对象copy属性到目的对象时,发现orderId为0. 经分析原来是一个低级错误导致,如下所示:  public long getOrderId() {     return orderId;   }   public void setOrderId(int orderId) {     this.orderId = orderId;   } 即set中的参数与get返回类型不同.将set中的参数由int改为long后

对象转换利器之Dozer

在Java的世界中,经常会涉及到需要在2个对象中进行转换,比如说: 调用SOAP Web服务,需要把自己的Domain对象转换为Soap服务的Jaxb对象请求, 在分层级SOA架构中,2个层级之间Domain对象的转换, 在分布式系统中,每个模块使用自己的领域对象,防止自己的业务被其他模块的domain对象影响 通常情况下,程序员们会自己弄一个Transformer层,来做对象之间的转换.估计很多同志在自己的项目代码中都可以看到Transformer的身影.但是,复杂的Java对象之间的转换并不

VO和DO转换(三) Dozer

VO和DO转换(一) 工具汇总 VO和DO转换(二) BeanUtils VO和DO转换(三) Dozer VO和DO转换(四) MapStruct Dozer 原文地址:https://www.cnblogs.com/rouqinglangzi/p/9470925.html