相关文章推荐
强健的皮带  ·  python - raise ...·  1 年前    · 
阳光的皮带  ·  c++那些事儿12.0 ...·  1 年前    · 
机灵的小熊猫  ·  异常详细信息: ...·  1 年前    · 
奔跑的草稿纸  ·  How do you handle a ...·  1 年前    · 

mapstruct 忽略某些字段值为空

MapStruct 提供了一种方便的方法,使用 @Mapping(target = "fieldName", ignore = true) 可以忽略将源对象的某个字段映射到目标对象的字段。你可以通过如下方式使用 ignore:

忽略空值:在源对象中,如果某个字段的值为 null,则可以通过 @Mapping(target = "fieldName", ignore = true) 忽略该字段。

忽略特定值:如果你想在源对象中忽略某个特定值,则可以使用 @Mapping(target = "fieldName", condition = "sourceFieldName != specifiedValue")。

@Mapper
public interface MyMapper {
  @Mapping(target = "field2", ignore = true)
  Target map(Source source);
              saltire
          JavaScript