1.pom文件
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper-spring-boot-starter</artifactId>
<version>1.2.5</version>
</dependency>
2.配置文件
logging.level.com.testspringboot2.dao.CustomerMapper=debug
spring.datasource.url=jdbc:mysql://127.0.0.1:3306/test?useUnicode=true&characterEncoding=utf-8&&useSSL=true
spring.datasource.username=root
spring.datasource.password=root
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
pagehelper.helperDialect=mysql
3.dao
@Select("SELECT * FROM customer")
List<Customer> getUserList();
4.测试
@Test
public void test() {
PageHelper.startPage(1, 3);
List<Customer> list = mapper.getUserList();
PageInfo<Customer> pageinfo = new PageInfo<Customer>(list);
int count = (int) pageinfo.getTotal();
System.out.println("count:"+count);
for(Customer c:pageinfo.getList()) {
System.out.println(c.getId()+" "+c.getAge()+" "+c.getGender());
}
}
5.结果
2019-11-15 17:27:45.610 DEBUG 10228 --- [ main] c.t.d.CustomerMapper.getUserList_COUNT : ==> Preparing: SELECT count(0) FROM customer
2019-11-15 17:27:45.632 DEBUG 10228 --- [ main] c.t.d.CustomerMapper.getUserList_COUNT : ==> Parameters:
2019-11-15 17:27:45.666 DEBUG 10228 --- [ main] c.t.d.CustomerMapper.getUserList_COUNT : <== Total: 1
2019-11-15 17:27:45.668 DEBUG 10228 --- [ main] c.t.dao.CustomerMapper.getUserList : ==> Preparing: SELECT * FROM customer LIMIT ?
2019-11-15 17:27:45.669 DEBUG 10228 --- [ main] c.t.dao.CustomerMapper.getUserList : ==> Parameters: 3(Integer)
2019-11-15 17:27:45.671 DEBUG 10228 --- [ main] c.t.dao.CustomerMapper.getUserList : <== Total: 3
count:4
41 1111 1
42 0 2
43 20 1