UserPageRepository


/**
* 他是具有分页和排序的功能 同时继承了 CrudRepository
*/
public interface UserPageRepository extends PagingAndSortingRepository<User,Long> {
}
1
2
3
4
5
UserPageRepositoryTests:

@RunWith(SpringRunner.class)
@SpringBootTest
public class UserPageRepositoryTests {

@Autowired
private UserPageRepository userPageRepository;

/**
* 排序查询
*/
@Test
public void findAllBySort() {
List<User> userList = (List<User>) userPageRepository.findAll(new Sort(Sort.Direction.ASC, "age"));
System.out.println(userList.size());
System.out.println(userList);
}

/**
* 分页查询
*/
@Test
public void findAllByPageable() {
Page<User> userPage = userPageRepository.findAll(new PageRequest(0, 20));
userPage.getNumber();//页数
userPage.getContent();//分页的数据
userPage.getTotalPages();//总共的页数
System.out.println("number:" + userPage.getNumber(http://www.amjmh.com/v/BIBRGZ_558768/)
+ "Countet" + userPage.getContent().size()
+ "TotalPages" + userPage.getTotalPages());
}

}

 

posted @ 2019-08-17 19:11  水至清明  阅读(169)  评论(0编辑  收藏  举报