Home > Back-end >  Ask a mapstruct problem, is a bit complicated, do not to come out, come in
Ask a mapstruct problem, is a bit complicated, do not to come out, come in

Time:03-13

Existing such kind of structure is simplified, as follows:
Class Root
{
String str_Root;
A, _a.
B _b;
.
}

Class B
{
String str_B;
.
}

Use mapstruct defined in the interface, now part of the code is as follows:
//root mapping
@ the Mappings ({
@ Mapping ()
.
})
Root map (Root obj)
.
//class A map
.
//class B mapping
//demand: if str_Root=="AB", the B.s tr_B="ABC", otherwise the same
@ the Mappings ({
@ Mapping (target="str_B," expression="Java (obj) getStr_Root (.) the equals (" AB")?" ABC ": obj. GetStr_Root ())
})
B mapRootToB (Root obj);

The question now is called the Root map (Root obj) B mapRootToB (Root obj) will not be called, but you can direct call mapRootToB B (Root obj) and returns the result is right,
Look at the compiled code, mapRootToB not be invoked in the Impl class, this is a special mapRootToB parameters Root, is to return the result B at the next higher level object, don't know if this reason, a great god analysis,
  • Related