The constructors PageRequest(...) is deprecated

尝试spring data的分页功能,从一本书上看的代码,写法如下:

Page<Device> pageDevice = repo.findAll(new PageRequest(1, 10, Sort.Direction.DESC, "createdate"));
		

但发现IDE有提示,说是目前这个PageRequest的构造方法过时了,想着最新的写法是什么?

从StackOverFlow找到了答案:https://stackoverflow.com/questions/44848653/pagerequest-constructors-have-been-deprecated

最新的写法如下:

Page<Device> pageDevice = repo.findAll(PageRequest.of(1, 3));

PageRequest.of

猜你喜欢

转载自blog.csdn.net/zhouyingge1104/article/details/85332166