Oracle使用mybatis分页插件-PageHandler

1. 依赖jar包(https://blog.csdn.net/qq_16517483/article/details/72803043)

使用 PageHelper 你只需要在 classpath 中包含 pagehelper-x.x.x.jar  jsqlparser-0.9.5.jar

2.mybatis-config.xml(https://blog.csdn.net/s592652578/article/details/78179998?locationNum=4&fps=1)

4.0.0版本之前:

  1. <plugins>  
  2.         <--
  3.         <plugin interceptor="com.github.pagehelper.PageHelper">  
  4.             <!-- 设置数据库类型 Oracle,Mysql,MariaDB,SQLite,Hsqldb,PostgreSQL六种数据库-->         
  5.             <property name="dialect" value="Oracle"/>  
  6.         </plugin>  
  7.     </plugins> 
4.0.0版本之之后:

  1. <plugins>  
  2.         <plugin interceptor="com.github.pagehelper.PageInterceptor">  
  3.             <!-- 设置数据库类型 Oracle,Mysql,MariaDB,SQLite,Hsqldb,PostgreSQL六种数据库, 4.0.0以后版本支持自动识别数据库-->       
  4.             <!-- <property name="dialect" value="Oracle"/>-->     
  5.         </plugin>  
  6.     </plugins> 

3.PageHandler


public void testPageHelper() {
    //这句一定要写在sql执行之前,只对紧跟的第一条语句起作用
    PageHelper.startPage(1, 5,"id desc");
    List<Dept> deptList = session.selectList("DEPT.getAllDept");
    PageInfo<Dept> page = new PageInfo<>(deptList);
    System.out.println("总页数:" + page.getPages());
    System.out.println("页码:" + page.getPageNum());
    System.out.println("总条数:"+page.getTotal());
    System.out.println(deptList.size());
    for (Dept dept : deptList) {
        System.out.println(dept.getName());
    }
}

猜你喜欢

转载自blog.csdn.net/houlai_houlai/article/details/80203306