我的问题是,spring数据库不会搜索搜索类的子类 . 例如:
模型:
@Document
class A {
@Id
String id
}
@Document
class B extends A {}
和存储库:
public interface ARepository extends PagingAndSortingRepository<A, String>{
Page<A> findAll(Pageable pageable);
}
Spring数据couchbase生成查询,具有where条件
_class =“com.example.model.A”
但是我想在这个查询中搜索B文件 . 在某种程度上,我该怎么做?当我编写自己的查询时,我必须在查询中定义顺序,限制和偏移,并且不使用Pageable . 但我想使用Pageable .
1 回答
考虑基于继承的通用接口 .
首先创建超级类:
然后创建您的子类:
创建基础存储库:
}
然后基于基础仓库创建SuperClass存储库:
SuperClassRepository
findAll()
将搜索所有A和B类