基于springBoot的jpa分页使用方法
1.对应dao层的代码
package com.yzy.sell.Repository; import com.yzy.sell.Entity.OrderMaster; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; import org.springframework.data.jpa.repository.JpaRepository; public interface OrderMasterRepository extends JpaRepository<OrderMaster,String> { //返回的Page类型,传入的参数是Pageable注意别导错包 Page<OrderMaster> findByBuyerOpenid(String BuyerOpenid, Pageable pageable); }
2.junit测试:
public void findByBuyerOpenid() { PageRequest request=PageRequest.of(0,2); //使用PageRequest,是Page的子类 Page<OrderMaster> byBuyerOpenid = repository.findByBuyerOpenid(OPENID, request); Assert.assertNotEquals(0,byBuyerOpenid.getTotalElements()); System.out.println(byBuyerOpenid.getContent().get(0)); }