gpt4 book ai didi

spring - Spring Data Mongodb Reactive 存储库中 findAll 方法的分页

转载 作者:行者123 更新时间:2023-12-03 21:57:34 27 4
gpt4 key购买 nike

已经有 question about paginationReactiveCrudRepository .接受的解决方案适用于遵循 findBy 的查询格式。项目文档还引用了该用法:

https://docs.spring.io/spring-data/mongodb/docs/current/reference/html/#mongo.reactive.repositories.usage

Example 158. Basic repository interface to persist Person entities

public interface ReactivePersonRepository extends
ReactiveSortingRepository<Person, String> {

Flux<Person> findByFirstname(String firstname);


Flux<Person> findByFirstname(Publisher<String> firstname);


Flux<Person> findByFirstnameOrderByLastname(String firstname,
Pageable pageable);

Mono<Person> findByFirstnameAndLastname(String firstname, String
lastname);

Mono<Person> findFirstByLastname(String lastname);
}


问题是这不适用于 findAll:
interface CustomerRepository : ReactiveCrudRepository<Customer, String> {
fun findAll(pageable: Pageable): Flux<Customer>

异常(exception):
Caused by: org.springframework.data.mapping.PropertyReferenceException: No property findAll found for type Customer!

Spring Data MongoDB 是否以某种方式支持这一点?

最佳答案

首先findAll(Pageable pageable)PagingAndSortingRepository的方法. Spring数据支持方法查询使用findByfindAll(Pageable pageable) 无关.

目前 Reactive Spring Data MongoDB 不支持任何方法,如 findAll(pageable: Pageable)但有一种方法可以做到。

interface CustomerRepository : ReactiveSortingRepository<Customer, String> {
fun findByIdNotNull(pageable: Pageable): Flux<Customer>
}

您可以从 here 阅读更多详细信息

关于spring - Spring Data Mongodb Reactive 存储库中 findAll 方法的分页,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61223834/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com