简体   繁体   中英

Hibernate setMaxResults paging

如果我没有设置setFirstResult(-)并每次都递归调用criteria.setmaxresults(10) ,它将自动从数据库中获取接下来的10个项目吗?

No. You have to use criteria.setFirstResult(0) and page through yourself, something like this:

public List getCarters(final int firstResult, final int maxResults) {

    final Criteria criteria = sessionFactory.getCurrentSession()
                      .createCriteria(SomePersistentClass.class);
                      .add(Restrictions.eq("name", "Carter"))
    criteria.setFirstResult(firstResult);
    criteria.setMaxResults(maxResults);

    return criteria.list();
}

Of course, no. Criteria grabs data from database only when you call .list() or .uniqueResult()

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM