[英]How can I get the total number of pages on Spring Data?
我有一個顯示實體列表的 Angular 應用程序,我有一個“顯示更多”按鈕可以增加頁碼並使用此方法:
Page<myEntity> result = myRepo.findByAttr(attr, page);
我格式化這個result
並通過 REST 的 JSON 發送它。 如果沒有其他頁面要獲取,我想禁用“顯示更多”按鈕。 有一個“框架”特定的方法來檢索這個數字,或者我應該使用findAll()
並通過這個列表進行計數?
這是Page
界面的源碼
public interface Page<T> extends Slice<T> {
/**
* Returns the number of total pages.
*
* @return the number of total pages
*/
int getTotalPages();
/**
* Returns the total amount of elements.
*
* @return the total amount of elements
*/
long getTotalElements();
/**
* Returns a new {@link Page} with the content of the current one mapped by the given {@link Converter}.
*
* @param converter must not be {@literal null}.
* @return a new {@link Page} with the content of the current one mapped by the given {@link Converter}.
* @since 1.10
*/
<S> Page<S> map(Converter<? super T, ? extends S> converter);
}
你有getTotalElements()
來獲取匹配元素的總數。
getTotalPages()
將給出總頁數。
使用result.getTotalElements()
獲取匹配元素的總數。
使用result.getTotalPages()
獲取總頁數。
ps 使用result.getContent()
獲取內容為 List<>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.