-3

我想将“ownDemand”作为需求页面返回。我怎样才能做到这一点

@Override
public Page<Demand> getDemandbyId(Long id, Pageable pageable) {
   Iterable<Demand> alldemand = demandRepository.findAll(); 
   List<Demand> ownDemand = new ArrayList<Demand>();
   for (Demand demand : alldemand) {
       if(demand.getStore().getId()==id) {
           ownDemand.add(demand);
       }
  }
    return null;
 }
 }

需求库

@RestResource
public interface DemandRepository extends JpaRepository<Demand,Long> {
}
4

2 回答 2

0

为什么不像这样向您的 DemandRepository 添加方法

Page<Demand> findAllByStore(Store store, Pageable page)

当然,这假定 StoreEntity 与 Demand 相关。

于 2020-08-10T05:16:04.703 回答
-1

试试下面:

demandRepository.findAll(PageRequest.of(0, 2))

通过签名它返回页面。根据您的适合更改 PageRequest。

于 2020-08-09T20:30:46.887 回答