How to Use MapStruct mapping from non-iterable to iterable?

问题描述 投票:0回答:0
List<MapStructureObjectEntity> toEntityTest(UUID mapId, MapStructureObjectDto.Update update);
List<MapStructureObjectEntity> toEntityTestList(UUID mapId, List<MapStructureObjectDto.Update> updateList);

我有一个从 List 转换为 List 的映射器,如上所示。

我知道为什么它不起作用。这是因为有一个称为 UUID 的不可重复字段,如果您排除 UUID,它会正常工作。

我想将 UUID mapId 包含在所有正在转换的数据中。

至此,列表已经在Stream(或For)方法中用mapId单独映射了

updateList.stream().map(update -> MapStructureObjectMapper.MAPPER.toEntity(mapId, update)).toList();

我不认为这是一种干净的方式,因为它做了两次工作。 (最重要的是,代码是去中心化的。哦该死!)

有没有方便的方法将其转换为 MapStruct?

java spring mapstruct
© www.soinside.com 2019 - 2024. All rights reserved.