简体   繁体   中英

Mapping two java object have same fields

I want to map the fields of two java objects based on condition like below.

if(sourceObject.getField1() != null && targetObject.getField1() == null){
     targetObject.setFields1(sourceObject.getField1())

}

I am using mapstruct @MappingTarget annotation but it is not giving me what I am expecting like above. I have multiple classes/subclasses with a hundred fields. Any suggestions or examples will help.

Not a generic solution but if you have to do specific things, you can do it in a @AfterMapping annotated method.

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