简体   繁体   中英

Dozer Mapping from string to Object

I have: _class A contains attributes: String userId, String a, String b. How can I use Dozer Mapping to map class A to class B (and otherwise) _class B has attributes: User user(object), String a, String b. _'User' is also a class whose id is userId Thanks for all help!

You can do like this , with the assumption your class A and B look like this :

 Class A{
 String userId;
 String a;
 String b;
 }

 Class B{
 User user;
 String a;
 String b;
 }

 Class User{
 String userId;
 }

You have add below mapping in your mapping ".xml" file.

   <mapping> 
      <class-a>com.techidiocy.example.A</class-a>
      <class-b>com.techidiocy.example.B</class-b>   
        <field>
           <a>userId</a>
           <b>user.userId</b>
        </field>
   </mapping>  

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM