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.                      
  5.             <property name="dialect" value="Oracle"/>  
  6.         plugin>  
  7.     plugins> 
4.0.0版本之之后:

  1. <plugins>  
  2.         <plugin interceptor="com.github.pagehelper.PageInterceptor">  
  3.                    
  4.                  
  5.         plugin>  
  6.     plugins> 

3.PageHandler


public void testPageHelper() {
    //这句一定要写在sql执行之前,只对紧跟的第一条语句起作用
    PageHelper.startPage(1, 5,"id desc");
    List deptList = session.selectList("DEPT.getAllDept");
    PageInfo 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());
    }
}

你可能感兴趣的:(java)