我有两个类order和targetorder
class Order {
Location location;
Address address;
}
class Location{
double lat;
double lng;
}
class Address{
.
.
.
}
目标顺序如下所示:
class TargetOrder{
TargetAddress targetAddress;
}
class TargetAddress{
double lat;
double lng;
.
.
.
}
现在我已经为address到targetaddress编写了mapstructMap;
比如说:
@Mapper(componentModel = "spring", unmappedTargetPolicy = ReportingPolicy.IGNORE)
public interface OrderMapper {
@Mapping(...)
@Mapping(...)
TargetAddress mapAddressToTargetAddress(Address address);
@Mapping(target = "targetAddress", source = "address")
@Mapping(target = "targetAddress.lat", source = "location.lat")
@Mapping(target = "targetAddress.lng", source = "location.lng")
TargetOrder mapOrderToTargetOrder(Order order);
当我这么做的时候, mapOrderToTargetOrder
实现不使用现有的 mapAddressToTargetAddress
但如果我移除
@Mapping(target = "targetAddress.lat", source = "location.lat")
@Mapping(target = "targetAddress.lng", source = "location.lng")
然后mapper使用现有的 mapAddressToTargetAddress
.
我想使用现有的MapMap,然后Map位置属性以及。我试过使用 @MappingTarget
它也不起作用。
有没有其他方法来实现这一点?
1条答案
按热度按时间gblwokeq1#
尝试使用mapstruct
@Named
注解并指定附加的qualifiedByName
中的参数@Mapping
注解。