问题描述
我有一个名为 Stock 和 Branch 的实体。现在我需要映射到dto的情况,但是dto中的一个字段来自另一个实体
public class Stock implements Identifiable {
@Id
@Basic
@GeneratedValue(strategy = GenerationType.AUTO)
private UUID id;
private String name;
private String code;
@ManyToOne(fetch = FetchType.LAZY)
private StockStatus stockStatus;
}
实体分支
public class Branch implements Identifiable {
@Id
@Basic
@GeneratedValue(strategy = GenerationType.AUTO)
private UUID id;
private String name;
private String address;
}
和DTO StockDto
public class StockDto {
@NotNull
@EqualsAndHashCode.Include
private UUID id;
@NotBlank
private String name;
@NotNull
private String code;
@NotNull
private UUID stockStatusId;
@NotNull
private UUID branchId;
}
所以我想将实体库存映射到StockDto。这是我的映射器类
@Mapper(config = MapStructConfig.class,uses = {
StockStatusMapper.class,})
public interface StockMapper {
@Mapping(source = "stockStatus",target = "stockStatusId")
StockDto toDto(Stock stock);
}
如何映射分支ID (实体分支的ID)? 我尝试使用@BeforeMapping和@AfterMapping,但未调用该方法。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)