首页 > 解决方案 > MapStruct - 不调用已定义的映射方法

问题描述

我在我们的项目中使用 MapStruct,我对映射方法的可重用性有疑问,我已经定义了这些映射方法并在不同的类中使用了这些方法。

我有这个方法StorageMapper

    fun toStorage(storage: StorageDao): Storage {
        return if (storage.container == null) {
            toLocationStorage(storage.location!!)
        } else {
            toContainerStorage(storage.container!!)
        }
    }

但是我不能以某种方式重用已经在LocationMapperor中定义的方法ResourceMapper,相反,我必须在下面定义这些方法

abstract fun toLocationStorage(location: LocationDao): Location

A 添加LocationMapper到映射器中@Mapper(uses = [LocationMapper::class]并在映射器中添加@Named("toLocation")注释,但我仍然无法重用它。

你有这方面的经验吗?非常感谢!

标签: javaspring-bootkotlinmapstruct

解决方案


推荐阅读