Springboot整合Mybatis 之分页插件使用

1: 引入jar包

<!-- 引入MyBatis分页插件-->
<dependency>
   <groupId>com.github.pagehelper</groupId>
  <artifactId>pagehelper</artifactId>
  <version>5.1.4</version>
</dependency>

 

2:在mybatis的xml配置文件中配置sql拦截

 <configuration>
     <settings>   
       .....
     </settings>
     <plugins>
           <plugin interceptor="com.github.pagehelper.PageInterceptor">
                   <property name="dialect"  value="com.github.pagehelper.PageHelper">
            </plugin>
      </plugins>
</configuration>

 

3: 使用分页

Page<Object> page = null;
if(pageSize != 0){
   //必须这样触发分页,只能生效一次,//true表示返回总记录数
   page = PageHelper.startPage(currentPage,pageSize,true); 
 }
//然后正常执行dao层的sql接口操作
List<DTO> list = DtoMapper.queryAll();
if(page != null){
   int totalRecord = page.getTotal();
}

 

posted @ 2018-06-03 16:25  老人与JAVA  阅读(897)  评论(0编辑  收藏  举报