Java MapStruct:如何在属性位于集合内且集合位于主实体内的情况下从复制中跳过特定属性

Java MapStruct:如何在属性位于集合内且集合位于主实体内的情况下从复制中跳过特定属性,java,collections,dto,mapstruct,Java,Collections,Dto,Mapstruct,我正在使用mapstruct更新现有bean。下面是我的豆子。正如您所看到的,我的实体bean有一个另一个实体bean的集合 public class Entity { private Integer id; private String name; private List<AnotherEntity> anotherEntityList = new ArrayList<AnotherEntity>(); //getters & setters } publi

我正在使用mapstruct更新现有bean。下面是我的豆子。正如您所看到的,我的实体bean有一个另一个实体bean的集合

public class Entity
{
private Integer id;
private String name;
private List<AnotherEntity> anotherEntityList = new ArrayList<AnotherEntity>();
//getters & setters
}

public class AnotherEntity
{
private Integer id;
private String text;
//getters & setters
}
更新时,我希望mapstruct跳过AnotherEntity bean中的id属性。 目前,它正在清除现有集合,并使用源中的值创建新集合

如果我在下面加上

@Mapping(target=“anotherEntityList”,ignore=true)
它正在忽略整个集合。但是我想要集合,但只忽略id属性。像这样的
@Mapping(target=“anotherEntityList.id”,ignore=true)


感谢您的帮助

MapStruct无法生成列表映射。它不知道用户的实际意图。请看一看以获得更多解释

但是假设列表都是有序的,并且元素0需要映射到目标元素0、1到1,等等

你可以这样做:

@Mapper
公共接口MyMapper{
//你可能不需要退货,对吧?
void updateEntityWithEntity(Entity sourceEntity,@MappingTarget Entity targetEntity);
//您需要自己实现列表合并..MapStruct不知道您在这里的意图
默认的updateList(ListsourceList,@MappingTargetListtargetList){

对于(int i=0;iThanks。我也有同样的想法,但不知怎么的,它不起作用。它适用于toEntity、ToTo方法,但不适用于更新。我的意思是@MappingTarget。通常它会删除整个集合并添加来自DTO的集合。因此它不会调用您要求我添加的新方法。啊..我记得。Mapstruct无法生成运行列表更新方法。将元素映射设置为非更新,它将正常工作。我将在访问我的计算机后立即更新我的示例
Entity updateEntityWithEntity(final Entity sourceEntity, @MappingTarget final Entity targetEntity);