标签:Pageable sys out http cti getc bsp repo request
/**
* 他是具有分页和排序的功能 同时继承了 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());
}
}
标签:Pageable sys out http cti getc bsp repo request
原文地址:https://www.cnblogs.com/hyhy904/p/11369950.html