我有一个Base dto和一个扩展它的dto
public abstract class AbstractItem {
private String upc;
private String quantity;
//getter and setter for upc and quantity
}
public class OrderedItem extends AbstractItem {
private String orderId;
// getter and setter for orderId
}
然后我有一个我想从OrderedItem转换的模态 . 此模态扩展了基本模态
public abstract class AbstractModal {
private String qty;
public void setQty(String qty) {
this.qty = qty;
}
public String getQty() {
return qty;
}
}
public class ItemModal extends AbstractModal {
private String orderNbr;
private String upcNbr;
// getter and setter for orderNbr and upcNbr;
}
这是我使用Mapstruct的mapper函数
@Mapper
public interface DtoMapper {
@Mappings({
@Mapping(source = "orderedItem.orderId" target = "orderNbr"),
@Mapping(source = "orderedItem.upc" target = "upcNbr"),
@Mapping(source = "orderedItem.quantity" target = "qty")
})
ItemModal convert(OrderedItem orderedItem);
}
在编译期间我收到错误 Unknown property "qty" in result type test.modal.ItemModal.
Mapstruct是否支持基类的映射字段?如果是,请告诉我我的代码有什么问题?我使用的是java 8和mapstruct 1.2.0
编辑:在 AbstractModal
中为 qty
添加了getter和setter