zoukankan      html  css  js  c++  java
  • 分页——为Mybatis配置PageHelper

    1、pom.xml追加

    pagehelper : 4.1.4

    2、mappers.xml中追加

        <plugins>
            <plugin interceptor="com.github.pagehelper.PageHelper">
                <property name="dialect" value="mysql" />
                <property name="offsetAsPageNum" value="true" />
                <property name="rowBoundsWithCount" value="true" />
                <property name="pageSizeZero" value="true" />
                <property name="reasonable" value="false" />
                <property name="returnPageInfo" value="check" />
                <property name="params" value="pageNum=start;pageSize=limit;" />
            </plugin>
        </plugins>

    3、使用

    // 使用PageHelper的API,指定当前页码和每页实体个数
    PageHelper.startPage(3, BasicsConstant.DEFAULT_PAGE_SIZE);
    // 正常使用Mybatis,获得结果集
    List<UserPo> pos = userMapper.listBy(userSex);
    // 使用PageHelper的API,包装结果集
    PageInfo<UserPo> userPage = new PageInfo<>(pos);
    
    int a = userPage.getPageNum();//当前页的页码
    
    int b = userPage.getPageSize();//当前页有几条数据
    
    int c = userPage.getTotal();//结果集中有几条数据
    
    int d = userPage.getPages();//总共几页
    
    boolean g = userPage.isHasPreviousPage();//当前页是否有前一页
    
    boolean h = userPage.isHasNextPage();//当前页是否有后一页
    
    List<UserPo> posInPage = userPage.getList();//获得应该在当前页显示的数据的List
  • 相关阅读:
    python_网络编程struct模块解决黏包问题
    python_网络编程socket(UDP)
    python_网络编程socket(TCP)
    python_面向对象
    python_生成器
    python_迭代器
    linux实操_shell自定义函数
    linux实操_shell系统函数
    linux实操_shell读取控制台输入
    scrapy-redis 0.6.8 配置信息
  • 原文地址:https://www.cnblogs.com/deolin/p/7294757.html
Copyright © 2011-2022 走看看