java映射嵌套列表
我有一个包含嵌套对象列表的对象
@Getter
@Setter
@NoArgsConstructor
public class Notification {
private Long id
private Long statusId;
private List <External> external;
}
@Getter
@Setter
@NoArgsConstructor
public class External{
private Long externalId;
private LocalDate date;
}
Dto
@Getter
@Setter
@NoArgsConstructor
public class NotificationPayload {
private Long id;
private Long statusId;
private List <ExternalReferencePayload> external;
}
@Getter
@Setter
@NoArgsConstructor
public class ExternalReferencePayload {
private Long externalReferenceId;
}
制图员
@Mapper(componentModel = "spring")
public interface NotificationMapper{
public Notification dtoToNotification(NotificationPayload payload);
}
我搜索映射嵌套列表的方法
# 1 楼答案
为了对某些元素执行自定义映射,只需要定义一个映射方法,其余的由MapStruct负责。在您的示例中:
使用此方法,嵌套列表将使用
dtoExternal
映射方法来执行映射。使用@Mapping
可以控制externalId
和externalReferenceId
之间的映射应该如何进行