Mapstruct - 更新现有 bean 并忽略字段

问题描述 投票:0回答:2

我正在更新一个bean 根据文档

@Mapper
public interface CarMapper {
    void updateCarFromDto(CarDto carDto, @MappingTarget Car car);
}

是否可以告诉mapstruct忽略某个字段? F.e.我不希望 mapstruct 将

id
字段从
carDto
映射到
car
实体,如果我不定义主体并手动跳过
id
字段映射,mapstruct 将执行此操作。

如果目前不可能,是否有任何解决方法(与自己的实现不同)?

mapstruct
2个回答
4
投票

使用

@Mapping( target = "id", ignore = true )


0
投票

如果使用 (nullValuePropertyMappingStrategy = NullValuePropertyMappingStrategy.IGNORE) 尝试@Mapping(源=“id”,目标=“id”,忽略= true)

© www.soinside.com 2019 - 2024. All rights reserved.