+ -
当前位置:首页 → 问答吧 → hibernate+struts2分页查询

hibernate+struts2分页查询

时间:2011-09-25

来源:互联网

hibernate+struts2分页查询的问题,永远都是第一页,为什么第一条sql语句对,第二条变样了
首先sql语句第1条select top 3 people0_.ID_ as ID1_0_, people0_.uname as uname0_, people0_.password as password0_, people0_.repassword as repassword0_ from People people0_
第2条select top 6 people0_.ID_ as ID1_2_, people0_.uname as uname2_, people0_.password as password2_, people0_.repassword as repassword2_ from People people0_为什么第2条sql语句是查询6条,而不是3条呢
也就是说为什么我的pageSize增加了一倍,我是要排除(pageNow-1)*pageSize条,查询pageSize条,求解啊
private pageNow=1;
private pageSize=3;(set和get方法默认)
public List find(int pageNow,int pageSize){
Configuration c=new Configuration();
c.configure();
SessionFactory f=c.buildSessionFactory();
Session session=f.getCurrentSession();
@SuppressWarnings("unused")
Transaction r=session.beginTransaction();
Query query= session.createQuery("from People");
query.setFirstResult(pageSize*(pageNow-1));
query.setMaxResults(pageSize);
List list=query.list();
session.close();
return list;

作者: ld191474639   发布时间: 2011-09-25

用limite 不用 top

作者: chong800   发布时间: 2011-09-27

热门下载

更多