如果要使用PageHelper插件,其要求的Mybatis最低版本不能低于3.3,而我使用的是3.4.6版本的,使用的是maven工程构建;以下是pox.xml引入Mybatis以及与spring整合的包\分页插件的包
<!-- https://mvnrepository.com/artifact/org.mybatis/mybatis -->
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
<version>3.4.6</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.mybatis/mybatis-spring -->
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis-spring</artifactId>
<version>1.3.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.github.pagehelper/pagehelper -->
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper</artifactId>
<version>5.1.2</version>
</dependency>
在mybatis的配置文件sqlMapConfig.xml中的配置详情可以参照点击打开链接
<plugins>
<plugin interceptor="com.github.pagehelper.PageInterceptor"></plugin>
</plugins>
使用
@ResponseBody
@RequestMapping("/articleList")
public PageInfo<Article> getArticleList(@RequestParam(value="pn",defaultValue="1")int pn) throws Exception{
PageHelper.startPage(pn, 8);//开始的页码,每页的数据数量
List<Article> list = articleService.selectNewArticle();
PageInfo<Article> pageInfo = new PageInfo<Article>(list,8);
return pageInfo;
}
本文介绍如何在MyBatis中使用PageHelper插件实现分页功能。文章详细展示了PageHelper的集成步骤,包括依赖项的配置、在MyBatis配置文件中的设置及具体的使用代码示例。
5903

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



