[英]Calling Service With Pageable Parameter - Best Practice Question
我有一個服務MyMainService
,該服務調用同一包中的另一個服務MySecondaryService
。 該方法getPagesOfMyObjects
被稱為在MySecondaryService
返回類型的對象的頁面MyObject
,並且該方法的參數中的一個是Pageable
對象。 目前, MyMainService
與分頁無關。 但是,由於我需要在getPagesOfMyObjects
中調用getPagesOfMyObjects
方法, MySecondaryService
需要為其提供一個Pageable
對象,該對象不會排除我可能需要的任何記錄。 我當前的解決方案(不是很好)是將其作為Pageable
參數傳遞
public class MyMainServiceImpl implements MyMainService {
@Autowired
private MySecondaryService mySecondaryService
public void myMethod() {
Page<MyObject> pages = mySecondaryService.getPagesOfMyObjects(PageRequest.of(0, 10000));
List<MyObject> myObjects = pages.getContent();
//do stuff
}
}
如您所見,它的大小參數已硬編碼為10000。 對我來說,這不是好習慣。 有沒有更好的方法來致電此服務? 我沒有選擇重寫現有的getPagesOfMyObjects
方法。
最后,我使用Pageable.unpaged()
作為參數來代替PageRequest.of(0, 10000)
,它似乎有效。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.