英文:
Pageable in Spring boot
问题
我想要将"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> {
}
英文:
I want to return "ownDemand" as Page of demand. How can I do that
@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;
}
}
Demand Repository
@RestResource
public interface DemandRepository extends JpaRepository<Demand,Long> {
}
答案1
得分: 0
为什么不像这样为您的DemandRepository添加一个方法:
Page<Demand> findAllByStore(Store store, Pageable page)
当然,这假设StoreEntity与Demand相关联。
英文:
Why not add a method to your DemandRepository like so
Page<Demand> findAllByStore(Store store, Pageable page)
This assumes that StoreEntity is related to Demand, of course.
答案2
得分: -1
返回的翻译部分如下:
根据签名,它返回 Page
英文:
Try below:
demandRepository.findAll(PageRequest.of(0, 2))
By signature it returns Page<Demand>. Change PageRequest according to your fit.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论