我目前正在处理一个使用 SpringBoot 的项目。
我使用 Hibernate 创建了一个名为 configuration_documents 的表。该表可以存储我创建的不同类型的文档对象。
我创建的文档对象之一是 Index,我想检索 Index 数据,所以我创建了一个像这样的存储库:
public interface IndexRepository extends CrudRepository<Index, Long> {
}
我知道configuration_document表应该只有一个索引条目,否则只返回表中的第一个索引。实现这一点的最佳方法是什么?
在不修改 IndexRepository 的情况下,我目前正在考虑这样的事情(IndexRepository 是 Autowiring 的):
StreamSupport.stream(this.configurationRepository.findAll().spliterator(), false).
map(
return Index;
).//A Collector here perhaps?
谢谢。
最佳答案
因此,据我所知,您无法使用jpa
根据行号进行查询。在jpa
中,您必须指定一个By
参数来充当where 子句。引用official documentation对于您可以编写的查询方法。
关于java - 使用 SpringBoot CrudRepository 查找一个已知条目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44249828/