zoukankan      html  css  js  c++  java
  • JAVA分页总结

    JAVA分页总结

    环境:数据库用的是MYSQL

     

    不走1:前端页面增加“上一页,下一页”……

     

    <ahref="?startindex=<%=preindex%>&amp;pagesize=10">上一页</a>

     

    <ahref="?startindex=<%=nextindex%>&amp;pagesize=10">下一页</a>

     

     

    不走2JSP页面增加代码

    recordop c=   new recordop();

    c.request=request;

    ResultSet rs=c.list("uname");      //取得查询纪录

    Stringpreindex=c.getpreindex();

    String nextindex=c.getnextindex();

     

     

     

    不走3:后端JAVA增加以下3个方法用来计算上一页及下一页索引

     

    publicintpagesize=12;

        public String getpreindex()

        {

           int curindex=0;

           if(request.getParameter("startindex")==null)

               return"0";

           else

           {

               curindex=Integer.valueOf(request.getParameter("startindex"));

               int pre=curindex-pagesize;

               if(pre<0)

                  return"0";

               else

                  return String.valueOf(pre);

              

           }

          

          

        }

        public String getCurIndex()

        {

           int curindex=0;

           if(request.getParameter("startindex")==null)

               return"0";

           else

           {

               return (request.getParameter("startindex"));

                

              

           }

          

          

        }

       

        public String getnextindex()

        {

           int curindex=0;

           if(request.getParameter("startindex")==null)

           {

               int next=curindex+pagesize;

               return String.valueOf(next);

           }

                

           else

           {

               curindex=Integer.valueOf(request.getParameter("startindex"));

               int next=curindex+pagesize;         

               return String.valueOf(next);

              

           }

        }

     

     

    不走4:增加LIST方法,查询纪录:主要语句为

     

     

        String sql = "select *from vinrecord order by id desc limit "+getCurIndex()+","+String.valueOf(pagesize);

       

  • 相关阅读:
    Android EventBus解析
    wpf image 指定Stretch="None" 不拉伸的时候,仍然拉伸的解决办法
    当父级绑定了DataContext之内的数据源时,子级想重新绑回DataContext
    wpf 千位符 格式化字符串
    wpf 如果列表加载超多数据变的卡顿时,使用VirtualizingStackPanel
    wpf DataTemplate ColumnDefinition width equal
    wpf 自定义控件展开popup,点击popup之外的部分,popup不能自动关闭
    wpf listBox的item,滚动条拖到低部,底部内容不能完全显示的问题
    wpf 在Popup内的TextBox 输入法 不能切换
    wpf image blur
  • 原文地址:https://www.cnblogs.com/attilax/p/15200013.html
Copyright © 2011-2022 走看看