我創建如下的映射。如何將平面dto對象屬性(如街道,城市等)映射到域對象中的嵌套地址。當我嘗試,我得到了一個錯誤:使用映射映射嵌套對象
[ERROR] diagnostic: Unknown property "address.postalCode" in return type. @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
}
那麼有沒有其他解決方案來解決這個問題? 我認爲如果表達式在源代碼中會起作用! – TinyOS
@Gunnar在目標端嵌套仍不支持?如果是的話,那麼這個「目標側嵌套」是由龍箱支持的嗎? –