1.在maven工程中引入架包
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper-spring-boot-starter</artifactId>
<version>1.2.3</version>
</dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper-spring-boot-starter</artifactId>
<version>1.2.3</version>
</dependency>
2.编写测试代码
public class TestDataSource {
@Test
public void test1() throws SQLException{
ApplicationContext ac =
SpringApplication.run(MyBootApplication.class);
DataSource ds = ac.getBean("druid",DataSource.class);
System.out.println(ds);
System.out.println(ds.getConnection());
DeptDao deptDao = ac.getBean("deptDao",DeptDao.class);
@Test
public void test1() throws SQLException{
ApplicationContext ac =
SpringApplication.run(MyBootApplication.class);
DataSource ds = ac.getBean("druid",DataSource.class);
System.out.println(ds);
System.out.println(ds.getConnection());
DeptDao deptDao = ac.getBean("deptDao",DeptDao.class);
//PageHelper 分页 仅对紧跟后面一个查询有效 1 页数 5 条数
PageHelper.startPage(2,3);
List<Dept> list = deptDao.loadAll();
for(Dept dept:list){
System.out.println(dept.getDeptno()+" "+dept.getDname());
}
}
}