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!