I have a service MyMainService
that makes a call to another service MySecondaryService
within the same package. The method getPagesOfMyObjects
being called in MySecondaryService
returns a Page of objects of type MyObject
and one of the method's parameters is a Pageable
object. MyMainService
is, at present, not concerned with pagination. But because I need to call the getPagesOfMyObjects
method in MySecondaryService
I need to provide it with a Pageable
object that won't exclude any records that I might need. My current solution (not very good) is to pass this as the Pageable
parameter
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
}
}
As you can see it has 10000 hard-coded as its size parameter. This doesn't feel like good practice to me. Is there a better way to call this service? I don't have the option of re-writing the existing getPagesOfMyObjects
method.
最后,我使用Pageable.unpaged()
作为参数来代替PageRequest.of(0, 10000)
,它似乎有效。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.