我创建如下映射。如何将平面 dto 对象属性(如(街道、城市等))映射到域对象中的嵌套地址。当我尝试时出现错误:
[错误] 诊断:返回类型中的未知属性“address.postalCode”。@Mapping(source = "city", target = "address.city"),
@Mapper(componentModel = "spring", uses = {})
public interface CompanyMapper {
@Mappings({
@Mapping(source = "id", target = "id"),
@Mapping(source = "street", target = "address.street"),
@Mapping(source = "city", target = "address.city"),
@Mapping(source = "postalCode", target = "address.postalCode"),
@Mapping(source = "province", target = "address.province"),
})
DomainObject map(DtoObject dto);
还有课...
public class Address {
private String street;
private Integer streetNumber;
private String city;
private String postalCode;
private String province;
//getters and setters
}
public class DomainObject {
private String id;
private Address address;
//getters and setters
}
public class DtoObject {
private String id;
private String street;
private String city;
private String postalCode;
private String province;
//getters and setters
}