问题
In their documentation (here: http://mapstruct.org/documentation/dev/api/org/mapstruct/AfterMapping.html), they mention that @AfterMapping can be used with @Qualifier / @Named to filter, but I can't find it anywhere how to actually use it this way.
My best guess was to use it like this:
@Mapper
public abstract class CustomerMapper {
@Named("Test")
public abstract Customer map(CustomerDto dto);
@Named("Test")
@AfterMapping
public void doAfterMapping(@MappingTarget Customer customer) {
//do stuff
}
}
But that seems to do nothing (If I remove the @Named annotations it works, but it is also used in other methods, which I don't want).. Does anyone know how this needs to be used?
回答1:
I got help in their gitter chatrooms, if anyone is looking for the same thing, this is doable with @BeanMapping like this:
@Mapper
public abstract class CustomerMapper {
@BeanMapping(qualifiedByName = "Test")
public abstract Customer map(CustomerDto dto);
@Named("Test")
@AfterMapping
public void doAfterMapping(@MappingTarget Customer customer) {
//do stuff
}
}
来源:https://stackoverflow.com/questions/52746320/how-to-use-qualifier-or-named-with-aftermapping-in-mapstruct