Dozer to achieve copy between objects __ Open source Tools

Source: Internet
Author: User

In a project, you often encounter a process of value passing between layers of objects, such as having a persistent class ClassA in the data persistence layer, which can become Viewa in the view layer, and typically, if two classes are structured, the most commonly used is beanutils.copyproperties ( Src,aim) method assigns the value of one object to another object. But if the attribute is different or the name is different, then need Dozer to complete, through the flexible configuration, achieves the copy between the different objects.

As follows:
An XML configuration file: Dozerbeanmapping.xml[XML]  View Plain Copy  <?xml version= "1.0"  encoding= "UTF-8"?>   <! doctype mappings public  "-//dozer//dtd mappings//en"    "http:// ">   <mappings>        <!-- <class-a> Specifies the source object to be replicated,<class-b> the target object,<a> the source object's property name, <b> the target object's property name.        wildcard defaults to True, at which point the default is to map all properties, and if False, only the properties that are configured in the XML file.  -->       <configuration>            <stop-on-errors>false</stop-on-errors>            <date-format>MM/dd/yyyy HH:mm</date-format>            <wildcard>true</wildcard>        </configuration>   &NBSP;&NBSP;&NBsp; <mapping>           <class-a> com.njusc.view.boxview</class-a>           <class-b >com.njusc.view.DepView</class-b>           < field>               <a>boxid </a>               <b>depid </b>           </field>            <field>                <a>depName</a>                <b>depName</b>            </field> &nbsP     </mapping>   </mappings>  

Below two simple classes [Java]   View plain copy package com.njusc.view;       public class boxview  

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.