用Hibernate 实现分页

public List queryByStatus(int status, int currentPage, int lineSize)
throws Exception {
    List all = null;
    String hql = "FROM Question AS q WHERE q.status=? ORDER BY q.questiontime desc";
    Query q = super.getSession().createQuery(hql);
    q.setInteger(0, status);
    q.setFirstResult((currentPage - 1) * lineSize);
    q.setMaxResults(lineSize);
    all = q.list();
    return all;
}

 

你可能感兴趣的