Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/api/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 可在春季启动页面_Java_Spring_Spring Boot_Pageable - Fatal编程技术网

Java 可在春季启动页面

Java 可在春季启动页面,java,spring,spring-boot,pageable,Java,Spring,Spring Boot,Pageable,我想返回“ownDemand”作为demand页面。我该怎么做 @Override public Page<Demand> getDemandbyId(Long id, Pageable pageable) { Iterable<Demand> alldemand = demandRepository.findAll(); List<Demand> ownDemand = new ArrayList<Demand>(); for

我想返回“ownDemand”作为demand页面。我该怎么做

@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;
 }
 }
@覆盖
公共页getDemandbyId(长id,可分页){
Iterable alldemand=demandRepository.findAll();
List ownDemand=new ArrayList();
for(需求:alldemand){
if(demand.getStore().getId()==id){
ownDemand.add(需求);
}
}
返回null;
}
}
需求存储库

@RestResource
公共接口DemandRepository扩展了JpaRepository{
}
尝试以下操作:

demandRepository.findAll(第页请求,共(0,2))


通过签名,它返回第页。根据您的需要更改PageRequest。

为什么不在您的需求中添加一种方法呢

Page<Demand> findAllByStore(Store store, Pageable page)
页面findAllByStore(存储区,可分页页面)

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

请添加您的
DemandRepository
和类似
Demand
的实体类。你可以用pageable打电话给findAllmethod@User-Upvotedon'tsayThanks,但我不想要退货findAll我想要的是id为whan I instanciate Page=new Page()和其他我不知道怎么做的方法(排序号页…)的商店的退货要求,请不要。当您有大量的
需求
实例(内存、性能)时,这将导致问题。只需为它编写一个适当的查询(方法)。类似于
页面findAllByStoreId(长存储ID,可分页页面)
;这将返回您所需的内容,并使用数据库的功能,而不是提取内存中的所有内容并进行分页和筛选。但我不希望返回findAll我希望返回id为whan I instanciate Page=new Page()和其他我不知道如何检查的方法(排序号页…)的存储要求。看起来您的问题与此重复。
Page<Demand> findAllByStore(Store store, Pageable page)