dozer--third-party replication tool, Ouch, not bad!

Source: Internet
Author: User

Dozer simple point, is the Copy tool, is also the meaning of the Copy tool, the official explanation is: Dozer is a Java beans to Java beans Mapper that recursively copies data from the one object to another. Typically, these Java Beans would be a different complex types. Very straightforward, is the property between class and class copy, including complex properties, this is very good, um, look at the specific use

Introducing Maven

<dependency><groupId>net.sf.dozer</groupId><artifactId>dozer</artifactId>< Version>5.5.1</version></dependency>

Then write a simple tool class, as follows:

/** * Attribute Copy tool *  * @author Dan * */public class Dozerbeanmapperutil {private static dozerbeanmapper Mapper;private dozer Beanmapperutil () {}public static dozerbeanmapper getinstance () {  if (mapper==null) {mapper = new  Dozerbeanmapper ();} return mapper;}}

Because just do copy, personally think single case most suitable, then is how to use, hehe
public static void Main (string[] args) {Dozerbeanmapper dozer = dozerbeanmapperutil.getinstance (); User U1 =  new User (); U1.setname ("U1"); System.out.println (U1.getname ()); User U2 =  New User ();d ozer.map (U1, U2); System.out.println (U2.getname ());}
Very simple Main method, I just copy U1 to U2. Actually print out U2 's name is also U1, stating the success of the bar


Most of this approach is used on the Web server, the user submitted to the VO to the model, or the model to the individual needs of the VO, but it is important to note that if you are associated with Hibernate table, there will be a loop and other error phenomena, This often appears in classes and classes have @manytoone and @onetomany relationship, if there is, please find another way to solve it, generally still tried


Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

dozer--third-party replication tool, Ouch, not bad!

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: info-contact@alibabacloud.com 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.