11.2.3.2.7. ページネーション
QueryBuilder の maxResults プロパティーを設定すると、返される結果の数を制限できます。これは、結果セットのページネーションを実現するために startOffset の設定と併用できます。
// match all books that have "clustering" in their title
// sorted by publication year and title
// and return 3'rd page of 10 results
Query query = queryFactory.from(Book.class)
.orderBy("publicationYear", SortOrder.DESC)
.orderBy("title", SortOrder.ASC)
.startOffset(20)
.maxResults(10)
.having("title").like("%clustering%")
.build();
注記
フェッチされる結果が maxResults に制限されている場合でも、Query.getResultSize() を呼び出すことで、一致する結果の合計数を見つけることができます。