Page<ClassOrder> findByMember_MemberID(long id, Pageable pageable);
Controller代码:
public ModelAndView showsignupclass(int page){ ModelAndView mv=new ModelAndView("/user/user-showSignupClass.btl"); Member member=memberRepository.findAll().get(0); int size=5;
//按报名时间倒序
Sort sort = new Sort(Sort.Direction.DESC,"time");
PageRequest pageable=PageRequest.of(page,size,sort); Page<ClassOrder> pageObject=classOrderRepository.findByMember_MemberID(member.getMemberID(),pageable);
//获取pageObject的内容 List<ClassOrder> classOrders=pageObject.getContent(); //getTotalPages()返回总的页数 int totalPage=pageObject.getTotalPages(); //getTotalElements()返回总数 long count=pageObject.getTotalElements(); mv.addObject("count", count); mv.addObject("totalPage",totalPage); mv.addObject("classOrders",classOrders); return mv; }