1
//用Hibernate實現分頁
2
public List queryByStatus(int status, int currentPage, int lineSize)
3
throws Exception {
4
List all = null;
5
String hql = "FROM Question AS q WHERE q.status=? ORDER BY q.questiontime desc";
6
Query q = super.getSession().createQuery(hql);
7
q.setInteger(0, status);
8
q.setFirstResult((currentPage - 1) * lineSize);
9
q.setMaxResults(lineSize);
10
all = q.list();
11
return all;
12
}
13

2

3

4

5

6

7

8

9

10

11

12

13
