PersonRepsotory接口 public interface PersonRepsotory extends PagingAndSortingRepository<Person, Integer> {} 具體實(shí)現(xiàn) @Test public void PagingAndSortingRepository() { // pageNo從0開始 int pageNo = 6 - 1; int pageSize = 5; // PageRequest接口通常使用的起PageRequest實(shí)現(xiàn)類,,其中封裝了需要分頁的信息 PageRequest pageRequest = new PageRequest(pageNo, pageSize); Page<Person> page = personRepsotory.findAll(pageRequest); System.out.println("總記錄數(shù):" + page.getTotalElements()); System.out.println("當(dāng)前第幾頁:" + page.getNumber()); System.out.println("總頁數(shù)" + page.getTotalPages()); System.out.println("當(dāng)前頁面的list:" + page.getContent()); System.out.println("當(dāng)前頁面記錄數(shù):" + page.getNumberOfElements()); }
|
|