相关文章推荐
发呆的茴香  ·  python打印pdf ...·  1 年前    · 
力能扛鼎的钢笔  ·  K8S Flannel_not ...·  1 年前    · 
苦恼的麦片  ·  Java 异常处理 | 菜鸟教程·  1 年前    · 
酒量小的登山鞋  ·  python多线程之 ...·  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