2 回答

TA貢獻(xiàn)1824條經(jīng)驗 獲得超5個贊
將返回類型調(diào)整為Page<PostOutputDTO>而不是List<PostOutputDTO>。
將 a 轉(zhuǎn)換List<PostOutputDTO>為 a的最簡單方法Page<PostOutputDTO>是
public Page<PostOutputDTO> getTopicPosts(@PathVariable("id") UUID topicId, Pageable pageable) {
return new PageImpl<>(postService.getActivePosts(topicId, pageable));
}
更新:
我仍然沒有看到全貌,但我希望存儲庫方法返回Page實例,
Page<Post> findPostsByTopicAndDeactivatedAtIsNull(...);
Page<Topic> findAllByTypeAndDeactivatedAtIsNull(...);
所以問題來自于PostAssembler#toResources返回 a List,我們不準(zhǔn)確地將其轉(zhuǎn)換為Pageback 。
如果我理解正確,您正在利用ResourceAssemblerSupport將 an Iterable<Post>(更準(zhǔn)確地說, a Page<Post>)映射到 a List<PostOutputDTO>。
我的建議是不使用PostAssembler#toResources,堅持PostAssembler#toResource和Page#map:
postRepo.findPostsByTopicAndDeactivatedAtIsNull(topic, pageable)
.map(postAssembler::toResource);

TA貢獻(xiàn)1805條經(jīng)驗 獲得超9個贊
您必須從 spring 返回接口頁面:
頁面是對象列表的子列表。它允許獲取有關(guān)它在包含中的位置的信息。
看例子:
public Page<PostOutputDTO> getActivePosts(UUID topicId, Pageable pageable) {
Page<PostOutputDTO> list=postService.getActivePosts(topicId, pageable);
return list;
}
有關(guān)更多信息,請參閱參考
添加回答
舉報