spring-boot 集合mybatis 的github分页查询
一、依赖包
<!-- mysql 数据库驱动. -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
<!--
spring-boot mybatis依赖:
请不要使用1.0.0版本,因为还不支持拦截器插件,
1.1.1大家使用最新版本即可
-->
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>1.1.1</version>
</dependency>
<!-- 分页
MyBatis提供了拦截器接口,我们可以实现自己的拦截器,
将其作为一个plugin装入到SqlSessionFactory中。
-->
<!--分页-->
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper</artifactId>
<version>4.1.0</version>
</dependency>
二、加入PageHelper
@Configuration public class MyBatisConfiguration { @Bean public PageHelper pageHelper() { System.out.println("MyBatisConfiguration.pageHelper()"); PageHelper pageHelper = new PageHelper(); Properties p = new Properties(); p.setProperty("offsetAsPageNum", "true"); p.setProperty("rowBoundsWithCount", "true"); p.setProperty("reasonable", "true"); pageHelper.setProperties(p); return pageHelper; } }
三
@SpringBootApplication @MapperScan("com.fjm.*") //扫描该目录下的文件 public class App { public static void main(String[] args) { SpringApplication.run(App.class, args); } }
四、在controller查询方法中加入PageHelper
public List<User> find(Map map) { //添加分页查询条件 PageHelper.startPage(0, 2); return userService.find(null); }