【问题标题】:MapStruct source and destination property lookupMapStruct 源和目标属性查找
【发布时间】:2021-12-12 17:04:01
【问题描述】:

我正在从 ModelMapper 转换为 MapStruct 到目前为止一切顺利,除了对列表进行排序和过滤的情况 例如,如果我有从域对象到实体的映射:

@Mapping(source = "contact.address.line1", target = "contactAddressLine1")

我想从一个 api 过滤或排序 contactAddressLine1 然后我想查找源(或映射反转时的目标),以便我可以将其添加到动态 jpq 或 sql 查询中。

有没有办法用 MapStruct 做到这一点?

借助 ModelMapper,我能够创建 typeMap

modelMapper.createTypeMap(sourceClass, destinationClass);

以后

TypeMap<?, ?> typeMap = modelMapper.getTypeMap(sourceClass, destinationClass);

我可以使用此类型映射来查找源和目标属性映射,从而确定动态排序和过滤查询的正确字段

【问题讨论】:

    标签: mapstruct


    【解决方案1】:

    目前无法从 mapstruct 中检索字段映射信息。 mapstruct 的 github 上有几个关于此问题的功能请求:

    【讨论】:

      猜你喜欢
      • 2020-09-25
      • 1970-01-01
      • 1970-01-01
      • 2021-10-03
      • 2022-11-09
      • 1970-01-01
      • 2020-10-06
      • 2021-12-09
      • 2020-10-05
      相关资源
      最近更新 更多