我在实体上有多个标记接口和 MappedSuperclass-es,我想创建一个共享配置,以忽略一些实体特定的目标。
示例接口和类:
public interface LongPrimaryKey extends Serializable
public abstract class FeatureBaseEntity extends BaseEntity
public class MyEntity extends FeatureBaseEntity implements LongPrimaryKey
我在 MapperConfig 界面中执行以下操作:
@MapperConfig(
unmappedTargetPolicy = ReportingPolicy.ERROR,
mappingInheritanceStrategy = MappingInheritanceStrategy.AUTO_INHERIT_FROM_CONFIG
)
public interface CentralConfig {
@Mapping(target = "id", ignore = true)
LongPrimaryKey toLongPrimaryKey(Model model);
@Mappings({
@Mapping(target = "createdAt", ignore = true),
@Mapping(target = "modifiedAt", ignore = true)
})
BaseEntity toBaseEntity(Model model);
@Mappings({
@Mapping(target = "createdAt", ignore = true),
@Mapping(target = "modifiedAt", ignore = true),
@Mapping(target = "id", ignore = true)
})
<T extends BaseEntity & LongPrimaryKey> T toBaseEntityLongPrimaryKey(Model model);
}
@Mapper(config = CentralConfig.class)
public interface MyEntityMapper {
@Mappings({
@Mapping(...)
})
@InheritConfiguration(name = "toBaseEntityLongPrimaryKey")
MyEntity toMyEntity(MyFeatureModel myFeatureModel, @MappingTarget MyEntity entity);
}
这抛出以下内容:
[DEBUG] diagnostic MyEntityMapper.java:28: error: None of the candidates toLongPrimaryKey(), toBaseEntity() matches given name: "toBaseEntityLongPrimaryKey".
@InheritConfiguration(name = "toBaseEntityLongPrimaryKey")
^
[DEBUG] diagnostic MyEntityMapper.java:29: error: More than one configuration prototype method is applicable.
Use @InheritConfiguration to select one of them explicitly: LongPrimaryKey toLongPrimaryKey(Model model), BaseEntity toBaseEntity(Model model).
MyEntity toMyEntity(MyFeatureModel myFeatureModel, @MappingTarget MyEntity entity);
此功能尚未涵盖,还是我遗漏了什么?