java - MapStruct - 不调用已定义的映射方法
问题描述
我在我们的项目中使用 MapStruct,我对映射方法的可重用性有疑问,我已经定义了这些映射方法并在不同的类中使用了这些方法。
我有这个方法StorageMapper
fun toStorage(storage: StorageDao): Storage {
return if (storage.container == null) {
toLocationStorage(storage.location!!)
} else {
toContainerStorage(storage.container!!)
}
}
但是我不能以某种方式重用已经在LocationMapper
or中定义的方法ResourceMapper
,相反,我必须在下面定义这些方法
abstract fun toLocationStorage(location: LocationDao): Location
A 添加LocationMapper
到映射器中@Mapper(uses = [LocationMapper::class]
并在映射器中添加@Named("toLocation")
注释,但我仍然无法重用它。
你有这方面的经验吗?非常感谢!
解决方案
推荐阅读
- here-api - 在地理编码请求中指定地区时返回错误的城市
- azure - Azure Kubernetes Service 502 Bad Gateway 的 nginx-ingress 控制器
- django - 如何将模型对象用作 Django 复选框选项,然后以可迭代的方式保存选择?
- mysql - 从连接的表中获取结果
- python - 如何确保 Tensorflow 模型中的静态形状以便于 OpenVINO 转换?
- hive - 如何在分区数据上创建表
- javascript - 使用未定义的过滤器
- python - 从 HTML 页面获取数据
- javascript - 如何将正则表达式用于 18-99 的整数范围?
- python - Pyechant 和 Webtext 库问题