I'm trying to use separated @AfterMaping
/ @BeforeMapping
methods for 2 methods: toDto
and toPartialDto
, but MapStruct generates code, where all @AfterMaping
/ @BeforeMapping
methods are used. I tried rework my abstract class to interface, but the problem remains.
@BeanMapping(qualifiedByName = {"method1", "method2", "method3"})
public abstract MyDto toDto(MyEntity entity);
@Named("toPartialDto")
@BeanMapping(ignoreByDefault = true, qualifiedByName = {"method3", "method4"})
public abstract MyDto toPartialDto(MyEntity entity);
@Named("method1")
@BeforeMapping
protected void setField1Data(@MappingTarget MyDto target, MyEntity entity) {
//some code
}
@Named("method2")
@AfterMapping
protected void updateDto(@MappingTarget MyDto target, MyEntity entity) {
//some code
}
@Named("method3")
@AfterMapping
protected void resolveOwn(@MappingTarget MyDto dto) {
//some code
}
@Named("method4")
@AfterMapping
protected void mapPartial(@MappingTarget MyDto target, MyEntity entity) {
//some code
}
MapStruct doesn't ignore the qualifiers
. When you define multiple qualifiers in BeanMapping#qualifiedByName
MapStruct will try to match all of them. This is mostly meant for having a specific qualified class with qualified methods.
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.