假设我有这样的映射:
@Mapping(source = "parentId", target = "parent.id")
Child map(ChildDto dto, Parent parent);
现在我需要将 ChildDto 列表映射到 Child 列表,但它们都有相同的父级。我希望做这样的事情:
List<Child> map(List<ChildDto> dtoList, Parent parent);
但它不起作用。有机会做吗?
原文由 AlexB 发布,翻译遵循 CC BY-SA 4.0 许可协议
我找到了如何用装饰器实现它,谢谢@Gunnar 这是一个实现:
豆子
映射器
装潢师
I use
abstract class
, notinterface
for mapper, because in case ofinterface
you couldn’t exclude for generation methodmap(List<Child> children, Parent parent)
, and the生成的代码在编译时无效。