首页 > 编程语言 > 详细

Springboot整合Mybatis 之分页插件使用

时间:2018-06-03 16:56:32      阅读:193      评论:0      收藏:0      [点我收藏+]

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();
}

 

Springboot整合Mybatis 之分页插件使用

原文:https://www.cnblogs.com/domi22/p/9129530.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!