pageHelper的使用步驟,省略sql語句中的limit


1.引架包。注意版本問題

<dependency>
            <groupId>com.github.pagehelper</groupId>
            <artifactId>pagehelper</artifactId>
            <version>5.1.6</version>
        </dependency>

2.MyBatis 的總體文件中配置插件

 放到<environments default="development">之前  
           
       <plugins>  
          <!-- PageHelper4.1.6 -->   
          <plugin interceptor="com.github.pagehelper.PageHelper">  
               <property name="dialect" value="oracle"/>        
         </plugin>  
      </plugins>  
插件5.1以后interceptor不同,並且不需要指定數據庫名字 
<plugins>
        <plugin interceptor="com.github.pagehelper.PageInterceptor">
        </plugin>
    </plugins>

3.在service層返回值類型是pageInfo,

4.在實現類中

@Override
    public PageInfo getall(String classname, String classnum, int pageindex, int size,int[] ids,String classstate) {
        //封裝模糊查條件
        Map map =new HashMap();
        map.put("classname",classname);
        map.put("classnum",classnum);
        map.put("ids",ids);
        map.put("classstate",classstate);
        //使用PageInfo工具實現分頁,1、導架包2、配置mybatis.xml
        PageHelper.startPage(pageindex,size);//在執行查詢之前設置
        List list = classesMapper.getall(map);
        //將插入的集合存在PageInfo分頁工具中
        PageInfo pi = new PageInfo(list);
        return pi;
    }

5.獲得其他分頁的信息

 System.out.println("總條數="+pi.getTotal());  
         System.out.println("總頁數="+pi.getPages());  
         System.out.println("下一頁="+pi.getNextPage());  
         System.out.println("當前頁碼="+pi.getPageNum());  
         System.out.println("每頁顯示條數:"+pi.getPageSize());  

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM