我正在編寫調用Web服務的Java客戶端代碼。當我打電話給我的客戶的網絡服務之一,其接受輸入參數如下圖所示:Java與分頁
KalturaFilterPager pager = new KalturaFilterPager();
pager.pageIndex = 1;
pager.pageSize = 50;
所以,如果我有430條記錄,我需要改變輸入參數,每次喜歡的PageIndex = 2頁面尺寸= 50像這樣獲取所有記錄。
現在我的要求是我想檢索我的所有記錄在一個頁面。如何在不指定pageSize = 431的情況下執行此操作,因爲此記錄號可能在將來發生更改。
我的代碼是:
private static String getMediaMetadata() throws KalturaApiException,
IOException, ParserConfigurationException, SAXException {
getKalturaClient();
String country = null;
KalturaMediaService mediaService = client.getMediaService();
System.out.println("Got the mediaservice" + mediaService);
KalturaMediaEntryFilter filter = new KalturaMediaEntryFilter();
KalturaFilterPager pager = new KalturaFilterPager();
pager.pageIndex = 1;
pager.pageSize = 50;
KalturaMediaListResponse mediaResponse = mediaService.list(filter,
pager);
if (mediaResponse.totalCount > 0) {
System.out.println("mediaResponse.totalCount"
+ mediaResponse.totalCount);
// pager.pageSize = mediaResponse.objects;
List<KalturaMediaEntry> mediaEntriesList = mediaResponse.objects;
if (mediaEntriesList != null && mediaEntriesList.size() > 0) {
for (int i = 0; i < mediaEntriesList.size(); i++) {
System.out.println("mediaEntriesList.size()-------->"
+ mediaEntriesList.size());
KalturaMediaEntry media = mediaEntriesList.get(i);
if (media != null) {
System.out.println("Media ID -------->" + media.id);
KalturaMetadataListResponse metadataResp = getMetadata(media.id);
if (metadataResp != null && metadataResp.totalCount > 0) {
System.out.println("Got the metadataResp"
+ metadataResp.totalCount);
List<KalturaMetadata> metadataObjs = metadataResp.objects;
if (metadataObjs != null && metadataObjs.size() > 0) {
System.out.println("got the metadaobjs");
for (int j = 0; j < metadataObjs.size(); j++) {
KalturaMetadata metadata = metadataObjs
.get(j);
if (metadata != null) {
System.out
.println("metadata not null --------->"
+ metadata);
String xml = metadata.xml;
if (xml != null) {
System.out
.println("xml not null --------->"
+ xml);
country = parseXml(xml);
if (country != null) {
System.out
.println("Country Value --------->"
+ country);
}
}
}
}
}
}
}
}
}
}
return country;
}
閱讀該Web服務的文檔 –