2

我正在尝试获取我的对象的总页数,以便我能够调用最后一页。这是我使用的代码

Page<Message> firstPage = defaultMessageService.getMessage(user, user2, new PageRequest(0, 6));

        paginationModel.setMessagesPage(defaultMessageService.getMessage(user, user2, new PageRequest(firstPage.getTotalPages() - 1, 6)))
                .setResponseMessage("Successful")
                .setSuccessful(true);

在我的代码中,我调用了第一页,只是为了获得总页数,然后将总页数减一,得到最后一页。这是资源占用,因为我获得了页面的内容列表,我不打算使用的内容。有没有更好的办法 ?我只想要总页、大小、当前页

4

1 回答 1

0

if you want only last page then sort your data in descending order and then get the first page. is it possible to sort your data then your problem will be solved.

于 2018-06-03T18:36:47.480 回答