如何为多态类定义Repository接口
防爆.
abstract class Source { public String name }
class InternalSource extends Source { public int internalId }
class ExternalSource extends Source { public String contact }
现在我知道我无法定义类似的存储库接口
interface SourceRepo extends Repository<? extends Source, String>{....}
要么
interface SourceRepo extends Repository<Source, String> { ....}
定义简单的普通接口并且有一个implmentation类是唯一的方法吗?
解决方法:
让spring通过’_class’属性将mongo文档与java类映射关联起来会很好.
Mongo文档会像这样
{_id : "xxx", name : "abc", internalId : 123, _class = "...InternalSource" }
{_id : "xxx", name : "abc", contact: "John doe", _class = "...ExternalSource"}