Answer the question
In order to leave comments, you need to log in
How to get the number of responses after a query is executed?
Good afternoon.
There is such a request with pagination.
List<Pages> datarecord1 = Dao.getSession()
.createQuery("FROM Page as d WHERE d.dateTimeCreated BETWEEN :startTimeDate AND :endTimeDate ORDER By d.dateTimeCreated", Pages.class)
.setParameter("startTimeDate", startTimeDate)
.setParameter("endTimeDate", endTimeDate)
.setFirstResult(startResult)
.setMaxResults(onPage)
.stream()
.map(restConverterService::Pages)
.collect(Collectors.toList());
Answer the question
In order to leave comments, you need to log in
Receive as a separate request
long totalPages = (Long) Dao.getSession()
.createQuery("select count(*) from Page")
.uniqueResult();
count
relatively heavy function, it is better to cache the result, and reset the cache when the number of lines changes.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question