mybatis的分頁插件能省事,本章記錄的是 spring boot整合mybatis分頁插件。mysql
<!-- 分頁插件pagehelper --> <dependency> <groupId>com.github.pagehelper</groupId> <artifactId>pagehelper</artifactId> <version>5.0.0</version> </dependency> <dependency> <groupId>com.github.pagehelper</groupId> <artifactId>pagehelper-spring-boot-autoconfigure</artifactId> <version>1.2.3</version> </dependency> <dependency> <groupId>com.github.pagehelper</groupId> <artifactId>pagehelper-spring-boot-starter</artifactId> <version>1.2.3</version> </dependency> <!-- 分頁插件pagehelper -->
二、配置application.yml文件git
注意 pagehelper 是一級根目錄和 spring 同級github
spring: mvc: view: prefix: / suffix: .jsp datasource: url: jdbc:mysql://localhost:3306/myrec?characterEncoding=utf8&useSSL=true username: root password: m123456 driver-class-name: com.mysql.jdbc.Driver #配置分頁插件pagehelper pagehelper: helperDialect: mysql reasonable: true supportMethodsArguments: true params: count=countSql
/** * 按分頁查詢 */ @Override public PageResult findPage(int pageNum, int pageSize) { PageHelper.startPage(pageNum, pageSize); Page<Loginuser> page= (Page<Loginuser>) loginuserMapper.selectByExample(null); return new PageResult(page.getTotal(), page.getResult()); }
包別導錯了spring
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;