我有下面的 java 流函式,但我想使用 PostgreSQL 查詢來檢索相同的資訊,執行過濾器,如果可能的話收集到一個串列。我想在 repo 層中寫一個查詢,例如@Query("")但不確定要寫什么。表名是pop_responder,列名是pop_registrants。
public List<PopResponderDao> getAllPopResponders() {
return popResponderRepository
.findAll()
.stream()
.filter(responderDao -> responderDao.getPopRegistrationDaos().isEmpty())
.collect(Collectors.toList());
}
PopRegistrationDaos是型別Collection<PopRegistrationDao>。存盤庫層使用 JPA:
public interface PopResponderRepository extends JpaRepository<PopResponderDao, Long> {}
uj5u.com熱心網友回復:
目前不支持使用流與資料庫互動。
如果您只需要過濾資料,您可以使用 JPQL 查詢。Afilter基本上是WHEREJPQL 中的一個子句。
SELECT p FROM PopResponderDao p where p.popRegistrationDaos IS NOT EMPTY
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/441648.html
標籤:爪哇 PostgreSQL jpa
