• SQL分页


    package com.bdqn.zhp.util;

    import java.util.ArrayList;
    import java.util.List;

    /**
     * 分页组件 分页:内存分页和SQL分页
     *
     * 分页需要参数:
     *
     * 总记录数,每页显示条数
     *
     */
    public class PageBeanSQL<T> {
        private int totalSize;// 总记录数
        private int rowsPerPage = 5;// 每页显示条数
        private int totalPages = 0;// 总页数
        private int curPageNo = 1;// 当前页号
        private List<T> pageList = new ArrayList<T>();// 存放当前页显示的所有记录

        /**
         * 分页方法
         *
         * @param list
         *            : 所有记录
         * @param curPage
         *            : 当前页号
         */
        public void page() {

            // 计算页数
            if (this.totalSize % this.rowsPerPage == 0) {
                this.totalPages = this.totalSize / this.rowsPerPage;
            } else {
                this.totalPages = this.totalSize / this.rowsPerPage + 1;
            }

            if(curPageNo<=0){
                this.curPageNo = 1;
            }
            if(curPageNo>=this.totalPages){
                this.curPageNo = this.totalPages;
            }



        }
        
        /**
         * 设置页号,传入String参数,转换为int并赋值
         */
        public void setPageNo(String curPage){
            try {
                this.curPageNo = Integer.parseInt(curPage);
            } catch (Exception e) {
                this.curPageNo = 1;
            }
        }

        public int getTotalSize() {
            return totalSize;
        }

        public void setTotalSize(int totalSize) {
            this.totalSize = totalSize;
        }

        public int getRowsPerPage() {
            return rowsPerPage;
        }

        public void setRowsPerPage(int rowsPerPage) {
            this.rowsPerPage = rowsPerPage;
        }

        public int getTotalPages() {
            return totalPages;
        }

        public void setTotalPages(int totalPages) {
            this.totalPages = totalPages;
        }

        public int getCurPageNo() {
            return curPageNo;
        }

        public void setCurPageNo(int curPageNo) {
            this.curPageNo = curPageNo;
        }

        public List<T> getPageList() {
            return pageList;
        }

        public void setPageList(List<T> pageList) {
            this.pageList = pageList;
        }

    }

  • 相关阅读:
    swift 资料
    CI cookie 存放数组
    CI框架中 日志输出方法log_message()只允许输出字符串解决方案
    CI框架整合微信公共平台接口
    php中的 file_get_contents(‘php://input’)
    CI 框架购物车问题
    JQ 报表插件 jquery.jqplot 使用
    微信开发调试工具
    常用开源库
    字符集更改步骤,mysql乱码
  • 原文地址:https://www.cnblogs.com/baobeiqi-e/p/9884839.html
Copyright © 2020-2023  润新知