关于Mybatis的分页插件PageHelper的使用

如果要使用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;
		
				
	}



猜你喜欢

转载自blog.csdn.net/java_hzp/article/details/80549406