Я не уверен, что мне здесь не хватает. Моя настраиваемая логика применяется ко всем атрибутам String, а не только к одному, который я указал для target.
@ApiModel(value="ShopProduct")
@Data
public class ShopProductDTO {
private String description;
private String fullImagePath;
}
@Entity
@Table(name = "shop_product")
public class ShopProduct implements Serializable {
@Column(name = "desc")
private String description;
@Column(name = "thumb_path")
private String thumbPath;
//getters,setters
ImageMapper:
@Component
public class ImagePathMapper {
AppConfig appConfig;
public ImagePathMapper(AppConfig appConfig) {
this.appConfig = appConfig;
}
public String toFullImagePath(String thumbPath){
return appConfig.getImagePath() + thumbPath;
}
}
ShopProduct Mapper:
@Mapper(componentModel = "spring", uses = {ImagePathMapper.class})
@Component
public interface ShopProductMapper {
@Mapping(target = "fullImagePath", source = "thumbPath")
ShopProductDTO shopProductToShopProductDTO(ShopProduct shopProduct);
}
Сгенерированный класс mapstruct:
ShopProductDTO shopProductDTO = new ShopProductDTO();
shopProductDTO.setDescription( imagePathMapper.toFullImagePath( shopProduct.getName() ) );
shopProductDTO.setFullImagePath( imagePathMapper.toFullImagePath( shopProduct.getThumbPath() ) );
}
Почему поле описания также используется с toFullImagePath?
Разве этот @Mapping (target = fullImagePath, source = thumbPath) не должен указывать, что я хочу изменить только fullImagePath?