ssh分页

把查询到的数据封装到一个pagebean中,在根据前台传过来的currentpage实现上一页和下一页的查询把查询到的数据封装到一个pagebean中,在根据前台传过来的currentpage实现上一页和下一页的查询
思维简单化,不要绕圈

得到数据库表中的一条最大id的记录 Spring配置文件 用hibernate 分页时这样配置 <property name=”hibernateProperties”> <props> <prop key=”hibernate.dialect”>org.hibernate.dialect.MySQL5Dialect</prop> <prop key=”hibernate.show_sql”>true</prop>  <prop key=”hibernate.format_sql”>true</prop> </props> </property>

 

分页的前台页面显示<tr align=’center’ bgcolor=”#FFFFFF” height=”22″> <td> <s:if test=”#request.pageBean.hasPreviousPage”> <a href=”index.action?page=${request.pageBean.currentPage-1}”>上一页</a> </s:if> <s:else> 上一页 </s:else> </td> <td>第${request.pageBean.currentPage }页</td> <td> <s:if test=”#request.pageBean.hasNextPage”> <a href=”index.action?page=${request.pageBean.currentPage+1}”>下一页</a> </s:if> <s:else> 下一页 </s:else> </td> <td>总共${request.pageBean.totalPage }页</td> </tr>

分页数据库层的查询方法
//分页查询 public List queryForPage(String sql,int startindex,int pagesize){ Query query = getSessionFactory().openSession().createQuery(sql); query.setMaxResults(pagesize); query.setFirstResult(startindex); return query.list();
} //总记录数 public int getCount(String sql){ Query query = getSessionFactory().openSession().createQuery(sql); int count = query.list().size(); return count; }
分页中Action中的代码
//此处分页 int currentPage;        if(ServletActionContext.getRequest().getParameter(“page”)==null){        currentPage = 1;        }else{        currentPage = Integer.parseInt(ServletActionContext.getRequest().getParameter(“page”));        } String sql=”from TGonggao order by gonggaoId desc”; int count = gonggaoDAO.getCount(sql); Page pageBean = new Page(); pageBean.setCurrentPage(currentPage); pageBean.setPageSize(2);
pageBean.setTotalPage(Page.countTotalPage(pageBean.getPageSize(), count)); pageBean.setAllRow(count); pageBean.init(); sql=”from TGonggao order by gonggaoId desc”; List gonggaoList = gonggaoDAO.queryForPage(sql, Page.countOffset(pageBean.getPageSize(), currentPage), pageBean.getPageSize()); pageBean.setList(gonggaoList);

Map request=(Map)ServletActionContext.getContext().get(“request”); request.put(“gonggaoList”, gonggaoList); request.put(“pageBean”, pageBean); return ActionSupport.SUCCESS;

论文查重降重QQ群: 905165878
毕业设计毕业论文互助QQ群: 905165878
定制讲解加:QQ号: 884563046 (微信同Q号不常上)