JPA的JpaRepository接口extends PagingAndSortingRepository<T, ID>
PagingAndSortingRepository接口下有这个方法
Page<T> findAll(Pageable var1);
使用此方法可以抵御整个数据表进行分页查询
但是如果我们需要对一个表加入一些条件再去分页查询,比方说一个用户表,查询所有同年龄的用户,应该使用什么方法来查询
在repository类里如下:
public interface MyRepository extends JpaRepository<User,Integer>{ Page<user> findAllByAge(String age,Pageable pageable); }
至于controller类和service类这里就不列出了。