【发布时间】:2021-04-23 14:07:14
【问题描述】:
假设我有这些实体:
public class Address {
private String id;
private String address;
private City city;
}
public class City {
private int id;
private Department department;
private String zipCode;
private String name;
private Double lat;
private Double lng;
}
public class Department {
private int id;
private Region region;
private String code;
private String name;
}
public class Region {
private int id;
private String code;
private String name;
}
还有这个 DTO:
public class AddressDTO {
private String address;
private String department;
private String region;
private String zipCode;
}
在我的 DTO 中,我想映射
- 来自城市/部门/名称的部门
- 地区来自城市/部门/地区/名称
这是我的映射器:
@Mapper(componentModel = "spring")
public interface AddressMapper {
AddressDTO addressToAddressDTO(Address item);
}
【问题讨论】: