zoukankan      html  css  js  c++  java
  • mybatis的分页查询

    直接来上一段代码:

    接口

    public <E> List<E> queryList(String sqlId, int offset, int number) throws DaoException;

    实现类:

    @Override
        public <E> List<E> queryList(String sqlId, int offset, int limit) throws DaoException {
            try {
                return sqlSessionTemplate.selectList(sqlId, new RowBounds(offset, limit));
            } catch (Throwable e) {
                throw new DaoException(e.getMessage(), e);
            }
        }

    映射文件这样写

    <select id="queryList" parameterType=""
                resultMap="">
            select
            <include refid="Base_Column_List"/>
            from
            tabkename a
            WHERE 1 = 1
            limit #{offset}, #{limit}
        </select>

    再来个分页的工具参数类

    public class PageBean<T> implements Serializable {
        private Integer pageNum ;
        private Integer pageSize = 10;
        private Integer totalNum;
        private Integer totalPage;
        private Integer lastPage;
        private Integer startIndex = 1;
        private Integer endIndex;
        private Integer nextPage;
        private List<T> list;
    get() set()方法...
    }
     pageBean = new PageBean<>();
     pageBean.setPageNum(pageNum);
     pageBean.setPageSize(pageSize);

    /*总页数计算*/
    double totalPage = Math.ceil((int)totalCount / pageSize);
    pageBean.setTotalPage((int) totalPage);

    /*起始索引计算*/
    pageBean.setStartIndex((pageNum - 1) * pageSize);

    /*上一页下一页计算*/
    pageBean.setNextPage(pageNum+1);
    pageBean.setLastPage(pageNum-1);

    ok,基本完成,核心的是RowBounts的offset和limit的两个参数

  • 相关阅读:
    java synchronized
    Java多线程的常见例子
    List,ArrayList
    BufferedInputStream与BufferedOutputStream
    super,this
    ServletConfig与ServletContext
    [转] 编写高效的 CSS 选择器
    浏览器是怎样工作的:渲染引擎,HTML解析
    sublime插件insertDate显示ISO时间
    《十日谈》摘要1
  • 原文地址:https://www.cnblogs.com/otways/p/11550378.html
Copyright © 2011-2022 走看看