关于PageHelper插件的简单使用
-
导入相关依赖
<!-- https://mvnrepository.com/artifact/com.github.pagehelper/pagehelper --> <dependency> <groupId>com.github.pagehelper</groupId> <artifactId>pagehelper</artifactId> <version>5.2.0</version> </dependency> -
在spring-mybatis.xml配置文件中进行配置
<property name="plugins"> <set> <bean class="com.github.pagehelper.PageInterceptor"> <property name="properties"> <props> <prop key="helperDialect">mysql</prop> </props> </property> </bean> </set> </property> -
在controller类中使用
public String selectXXXXX(int pageIndex){ //设置查询的起始页及每页显示记录条数,其后必须紧跟查询语句 PageHelper.startPage(pageIndex, 3); List<Product> products = productService.findProductByMainName(category); //将查询到的记录放到PageInfo中,它会包装Page对象 PageInfo<Product> pageInfo = new PageInfo<>(products); }
本文介绍了如何在Spring Boot项目中利用PageHelper插件实现MySQL分页查询,包括依赖引入、配置文件设置和Controller中调用方法的步骤。
3126

被折叠的 条评论
为什么被折叠?



