我的映射器接口中是否可以有多个方法,几乎​​相同但具有不同的 return 对象?

Is it possible to have multiple methods in my mapper interface, almost the same but with different return object?

是否有可能在我的映射器接口中有 2 个方法,它们几乎相同但具有不同的 return 对象(字段数量较少)?我创建了一个比原始对象小的附加 DTO 对象(例如 MySmallDto)。我必须创建一个新的映射器接口还是可以在现有映射器中重用逻辑?

public interface SearchDtoMapper {
    @Mapping(target = "lPlace", source = "route", qualifiedByName = "SpotToLPlace")
    @Mapping(target = "uPlace", source = "route", qualifiedByName = "SpotToUPlace")
    MyBigDto map(Route route);

在同一个映射器中,我想要类似的东西:

    @Mapping(target = "lPlace", source = "route", qualifiedByName = "SpotToLPlace")
    @Mapping(target = "uPlace", source = "route", qualifiedByName = "SpotToUPlace")
    MySmallDto map(Route route);

MapStruct 可以有任意多的方法和任意多的源和 return 类型。

因此在您的示例中,您可以执行以下操作:

public interface SearchDtoMapper {
    @Mapping(target = "lPlace", source = "route", qualifiedByName = "SpotToLPlace")
    @Mapping(target = "uPlace", source = "route", qualifiedByName = "SpotToUPlace")
    MyBigDto map(Route route);

    @Mapping(target = "lPlace", source = "route", qualifiedByName = "SpotToLPlace")
    @Mapping(target = "uPlace", source = "route", qualifiedByName = "SpotToUPlace")
    MySmallDto mapSmall(Route route);
}