hibernate实现分页算法

[codes=java]
<%@ page language="java"
  import=”java.util.*,org.hibernate.SessionFactory,org.hibernate.cfg.Configuration,org.hibernate.*,idv.dean.*”
  pageEncoding=”gb2312″%>
<%
  String path = request.getContextPath();
  String basePath = request.getScheme() + “://”
      + request.getServerName() + “:” + request.getServerPort()
      + path + “/”;
%>
<%!int pageNo = 0;   int maxPage = -1;   int prevPage = 0;   int nextPage = 0;   int rsPerPage = 5;%>



  
    
    
    
    
    
    

  

  
    <%
      Configuration configd = new Configuration().configure();
      SessionFactory sessionfactory = configd.buildSessionFactory();
      org.hibernate.classic.Session hsession = sessionfactory
          .openSession();
      String npage = request.getParameter(“page”);
      if (npage == null) {
        pageNo = 0;
      } else {
        pageNo = Integer.parseInt(npage);
      }
      Integer count = (Integer) hsession.createQuery(
          “select count(id) from Userscore”).uniqueResult();
      maxPage = (count.intValue()-1) / rsPerPage;

      String hql = “from Userscore”;
      Query q = hsession.createQuery(hql);
      q.setFirstResult(pageNo * rsPerPage);
      q.setMaxResults(rsPerPage);
      List list = q.list();
      Iterator itr = list.iterator();

      out.println(“

“);
      out.println(“

“);
      out.println(“

“);
      while (itr.hasNext()) {
        Userscore score = (Userscore) itr.next();
        out.println(“

“);
        out.println(“

“);
        out.println(“

“);
        out.println(“

“);
        out.println(“

“);
        out.println(“

“);
        out.println(“

“);
      }
      tt.setId(1);
      tt.setScore(100);
      tt.setTestfile(“he:”);
      out.println(“

” + “考试编号”);
      out.println(“

” + “用户名”);
      out.println(“

” + “成绩”);
      out.println(“

” + “考试时间”);
      out.println(“

” + “考试文件”);
      out.println(“
” + score.getId() + “ ” + score.getUsername() + “ ” + score.getScore() + “ ” + score.getTesttime() + “ ” + score.getTestfile() + “

“);
    %>
    This is All test histroy
    
    

    <%
      out.println(“第一页“);
      if (pageNo > 0) {
        prevPage = pageNo – 1;
      } else {
        prevPage = 0;
      }
      out.println(“          + “\”>前一页“);
      if (pageNo < maxPage) {
        nextPage = pageNo + 1;
      } else {
        nextPage = maxPage;
      }
      out.println(“          + “\”>下一页“);
      out.println(“          + “\”>最后一页“);
    %>
  

[/codes]

“hibernate实现分页算法”的一个回复

发表评论

电子邮件地址不会被公开。 必填项已用*标注

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据