物理分页
每次去数据库中只查询一页的数据
点击下一页,去数据库中只查询第一页的数据
逻辑分页
把博客中的所有数据都查询回来了,放到内存,每次从内存中取一页的数据过来
SQL
select * from blog limit 1,2
1代表起始的位置,2代表访问的行数
pom.xml
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper</artifactId>
<version>5.3.2</version>
</dependency>
spring.xml
<property name="plugins">
<array>
<bean class="com.github.pagehelper.PageInterceptor"/>
</array>
</property>
mapper.java
@Select("select * from tbl_book")
List<Book> selectAll();
bookservice
PageInfo<Book> selectAll(Integer pageNo,Integer pageSize);
bookserviceImpl
@Override
public PageInfo<Book> selectAll(Integer pageNo, Integer pageSize) {
PageHelper.startPage(pageNo,pageSize);
List<Book> books = bookMapper.selectAll();
return new PageInfo<>(books);
}
bookcontroller.java
@RequestMapping("/findAll/{pageNo}/{pageSize}")
public R selAll(@PathVariable Integer pageNo,@PathVariable Integer pageSize) {
PageInfo<Book> bookPageInfo = bookService.selectAll(pageNo, pageSize);
return bookPageInfo!=null?new R(Code.GET_OK, "查询成功", bookPageInfo):new R(Code.GET_ERR, "查询失败", null);
}
标签:selectAll,分页,pageSize,pageNo,查询,Integer,PageInfo
From: https://www.cnblogs.com/YxinHaaa/p/17478684.html