是否有可能在我的映射器接口有多个方法,几乎相同,但有不同的返回对象?



是否可能有,例如,2个方法在我的映射器接口,几乎相同,但具有不同的返回对象(具有较小的字段量)?我创建了一个额外的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可以有任意多的方法、任意多的源类型和返回类型。

在你的例子中,你可以这样做:

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);
}

相关内容

  • 没有找到相关文章

最新更新