• 分页


    --------------action虚拟里分页------------------

    //从session中获取集合值
       List<F1111Repeat> list=null;
       if(null==session.getAttribute("F1111List")){   
        F1111 fmsg = new F1111();
        fmsg.setFlag(queryName);
        fmsg.setOperor(userName);
        fmsg.setCommpanyID(companyId);
        fmsg.setBeginDate(beginDate);
        fmsg.setEndDate(endDate);   
        fmsg.execute();
        list = fmsg.getReList();
        session.setAttribute("F1111List",list);
       }else{
        list=(List<F1111Repeat>) session.getAttribute("F1111List");
       }
       
       int totalNum=list.size(); 
       
       //计算取值的范围
       int beginPar=(current_page-1)*Configure.PAGESIZE+1;
       int endPar=(current_page-1)*Configure.PAGESIZE+Configure.PAGESIZE;
       if(endPar>totalNum){
        endPar=totalNum;
       }
      
       //分页拼装
       List<F1111Repeat> tranList =list.subList(beginPar, endPar);  
          Pager pager= new Pager();
          pager.paging(current_page, Configure.PAGESIZE, totalNum);  
          pager.setList(tranList);
          request.setAttribute("pager", pager);

    public class Pager {  
     
        private int total_page;     //总页数  
        private int total_count;    //总记录数  
        private int current_page;   //当前页  
        private int page_size;      //每页的数量  
        private int first_page;  
        private int pre_page;  
        private int next_page;  
        private int last_page;  
        private boolean is_first;  
        private boolean is_last;  
        private List list;  
          
        public List getList() {  
            return list;  
        }  
        public void setList(List list) {  
            this.list = list;  
        }  
        public int getTotal_page() {  
            return total_page;  
        }  
        public void setTotal_page(int total_page) {  
            this.total_page = total_page;  
        }  
        public int getTotal_count() {  
            return total_count;  
        }  
        public void setTotal_count(int total_count) {  
            this.total_count = total_count;  
        }  
        public int getCurrent_page() {  
            return current_page;  
        }  
        public void setCurrent_page(int current_page) {  
            this.current_page = current_page;  
        }  
        public int getPage_size() {  
            return page_size;  
        }  
        public void setPage_size(int page_size) {  
            this.page_size = page_size;  
        }  
        public int getFirst_page() {  
            return first_page;  
        }  
        public void setFirst_page(int first_page) {  
            this.first_page = first_page;  
        }  
        public int getPre_page() {  
            return pre_page;  
        }  
        public void setPre_page(int pre_page) {  
            this.pre_page = pre_page;  
        }  
        public int getNext_page() {  
            return next_page;  
        }  
        public void setNext_page(int next_page) {  
            this.next_page = next_page;  
        }  
        public int getLast_page() {  
            return last_page;  
        }  
        public void setLast_page(int last_page) {  
            this.last_page = last_page;  
        }  
        public boolean isIs_first() {  
            return is_first;  
        }  
        public void setIs_first(boolean is_first) {  
            this.is_first = is_first;  
        }  
        public boolean isIs_last() {  
            return is_last;  
        }  
        public void setIs_last(boolean is_last) {  
            this.is_last = is_last;  
        }  
          
        /** 
         * 分页处理 
         * @param current_page 当前页 
         * @param page_size 每页的数量 
         * @param total_count 总记录数 
         */ 
        public void paging(int current_page, int page_size, int total_count){  
            this.current_page = current_page;  
            this.page_size = page_size;  
            this.total_count = total_count;  
              
            if(current_page < 1){  
                this.current_page = 1;  
            }  
              
            this.total_page = (this.total_count + page_size - 1)/page_size;  
            this.first_page =1;  
            this.last_page = total_page;  
              
            if(this.current_page > 1){  
                this.pre_page = this.current_page - 1;  
            }else{  
                this.pre_page = 1;  
            }  
              
            if(this.current_page < total_page){  
                this.next_page = this.current_page + 1;   
            }else{  
                this.next_page = total_page;  
            }  
              
            if(this.current_page <= 1){  
                this.is_first = true;  
            }else{  
                this.is_first = false;  
            }  
              
            if(this.current_page >= total_page){  
                this.is_last = true;  
            }else{  
                this.is_last = false;  
            }  
        }  
          
    }

    <%@ page contentType="text/html;charset=UTF-8" %>
    <%@ taglib prefix="s" uri="/struts-tags"%>
    <script type="text/javascript">
    var total_page =${requestScope.pager.total_page};
    var action=document.forms[0].action;
    function goCommonPager(){
     var current_page=document.getElementById("goCommonPageNO").value;
     if(isNaN(current_page)||current_page<=0||current_page>total_page){
      alert("请输入1到"+total_page+"之间的正整数.");
      return false;
     }
     document.forms[0].action=action+"?current_page="+current_page;
     document.forms[0].submit();
    }
    function doCommonPager(current_page){
     document.forms[0].action=action+"?current_page="+current_page;
     document.forms[0].submit();
    }
    </script>
    <table width="100%" border="0" align="center" cellpadding="0" cellspacing="0" >
      <tr>
        <td height="30" width="100%" align="right">
       共${requestScope.pager.total_count}条  第${current_page}页/共${requestScope.pager.total_page}页
      <s:if test="#request.pager.is_first == false"> 
       <a href="javascript:doCommonPager(${requestScope.pager.first_page})">首页</a>
       <a href="javascript:doCommonPager(${requestScope.pager.pre_page})">上一页</a>
      </s:if>
      <s:if test="#request.pager.is_first == true"> 
       <a href="#">首页</a>
       <a href="#">上一页</a>
      </s:if>   
      <s:if test="#request.pager.is_last == false">  
       <a href="javascript:doCommonPager(${requestScope.pager.next_page})">下一页</a>
       <a href="javascript:doCommonPager(${requestScope.pager.last_page})">最后一页&nbsp;</a>
      </s:if>
      <s:if test="#request.pager.is_last == true">  
       <a href="#">下一页</a>
       <a href="#">最后一页&nbsp;</a>
      </s:if>
      <input id="goCommonPageNO" type="text" size="1"/>
               <input name="button" type="button"  value="Go" onclick="goCommonPager();"/> 
            </td>
      </tr>
    </table>

  • 相关阅读:
    linux下tomcat启动正常,但是外部浏览器无法访问
    mybatis中映射文件和实体类的关联性
    判断用户请求时使用的浏览器类型
    HTML地理位置定位
    使用jQuery的toggle()方法对HTML标签进行显示、隐藏操作
    jQuery怎么去掉标签的hover效果
    java与javascript
    sendRedirect 与forward的区别
    windows--添加程序到右键菜单中
    收集:word xml格式
  • 原文地址:https://www.cnblogs.com/yangy608/p/2324503.html
Copyright © 2020-2023  润新知