我可以使用 querydsl 谓词参数 return 来自 spring jpa 存储库的 Stream

Can i return a Stream from a spring jpa repository using a querydsl predicate argument

我正在使用 spring 数据并且有一个扩展 JpaRepository 和 QueryDslPredicateExecutor 的存储库。我通过调用 Iterable findAll(Predicate p) 方法从存储库中获取实体列表。我想知道,是否有可能从存储库中返回一个 Stream 并将 querydsl 谓词作为参数传递?

我认为现在不可能。检查这个问题:https://jira.spring.io/browse/DATACMNS-704

https://github.com/spring-projects/spring-data-commons/issues/1169#issuecomment-752400977 中所述,您可以声明自己的方法 returns List<...>

import java.util.List;

import org.bson.types.ObjectId;
import org.springframework.data.mongodb.repository.MongoRepository;
import org.springframework.data.querydsl.QuerydslPredicateExecutor;
import org.springframework.stereotype.Repository;

import com.querydsl.core.types.Predicate;

@Repository
public interface MyEntityRepository extends MongoRepository<MyEntity, ObjectId>, QuerydslPredicateExecutor<MyEntity> {

  List<MyEntity> findAll(Predicate predicate);
}

那么简单

myEntityRepository.findAll(myPredicate).stream()....