1、spring boot 自带分页工具类 org.springframework.data.domain.Pageable
1、spring boot 自带分页工具类 org.springframework.data.domain.Pageable
/**
* 假如page=1,size=5,则 limit 6,5 ,因为page代表索引页,从第0页开始,后面两个是排序的参数
*/
public PageRequest(int page, int size, Direction direction, String... properties) {
......
}
使用方法:
//@Service中,sellerFoodDao是继承 JpaRepository<SellerFoodE,Long>的接口,即可使用JPA查询到
Pageable pageable = new PageRequest(page - 1, Constant.PAGE_SIZE, Sort.Direction.ASC, "foodName");
sellerFoodDao.findByRestaurantAndFoodNameLike(rest, "%" + likeStr + "%", pageable);