而不是在查询注释中控制结果大小。
使用Pageable界面,以下内容取自文档。
public interface BookRepository extends ElasticsearchRepository<Book, String> {
@Query("{"bool" : {"must" : {"field" : {"name" : "?0"}}}}")
Page<Book> findByName(String name,Pageable pageable);
}
这将使您能够:
findByName("foo-name", new PageRequest(0,1));
如果您还想排序:
findByName("foo-name", new PageRequest(0,1, new Sort(new Sort.Order(Sort.Direction.ASC,"name")))).getContent().get(0);