zoukankan      html  css  js  c++  java
  • 分页插件PageHelper

    一、PageHelper说明

    如果你也在用Mybatis,建议尝试该分页插件,这个一定是最方便使用的分页插件。

    该插件目前支持Oracle,Mysql,MariaDB,SQLite,Hsqldb,PostgreSQL六种数据库分页。

    二、使用方法

    第一步:把PageHelper依赖的jar包添加到工程中。官方提供的代码对逆向工程支持的不好,使用参考资料中的pagehelper-fix。

       第二步:在Mybatis配置xml中配置拦截器插件:

    <plugins>
    <!-- com.github.pagehelper为PageHelper类所在包名 -->
      <plugin interceptor="com.github.pagehelper.PageHelper">
        <!-- 设置数据库类型 Oracle,Mysql,MariaDB,SQLite,Hsqldb,PostgreSQL六种数据库-->
        <property name="dialect" value="mysql"/>
      </plugin>
    </plugins>

       第三步:测试分页

    @Test
        public void testPageHelper() throws Exception {
            //初始化spring容器
            ApplicationContext applicationContext = new ClassPathXmlApplicationContext("classpath:spring/applicationContext-dao.xml");
            //获得Mapper的代理对象
            TbItemMapper itemMapper = applicationContext.getBean(TbItemMapper.class);
            //设置分页信息
            PageHelper.startPage(1, 30);
            //执行查询
            TbItemExample example = new TbItemExample();
            List<TbItem> list = itemMapper.selectByExample(example);
            //取分页信息
            PageInfo<TbItem> pageInfo = new PageInfo<>(list);
            System.out.println(pageInfo.getTotal());
            System.out.println(pageInfo.getPages());
            System.out.println(pageInfo.getPageNum());
            System.out.println(pageInfo.getPageSize());
        }
  • 相关阅读:
    .NET Framework Execution Was Aborted By Escalation Policy
    语句获取作业属性、历史记录
    Login failed知多少
    数据库代理错误日志
    微信小程序资料
    时间进度条,根据时间,显示任务进度条
    两个select 左右添加,上下移动
    图片轮播无缝接
    CSS3简单的栅格系统
    JavaScript DOM节点和文档类型
  • 原文地址:https://www.cnblogs.com/yft-javaNotes/p/10016220.html
Copyright © 2011-2022 走看看