pom中引包
<!--pagehelper-->
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper</artifactId>
<version>4.1.3</version>
</dependency>
启动类中的main方法上面插入代码
@Bean
PageHelper pageHelper(){
//分页插件
PageHelper pageHelper = new PageHelper();
Properties properties = new Properties();
properties.setProperty("reasonable", "true");
properties.setProperty("supportMethodsArguments", "true");
properties.setProperty("returnPageInfo", "check");
properties.setProperty("params", "count=countSql");
pageHelper.setProperties(properties);
//添加插件
new SqlSessionFactoryBean().setPlugins(new Interceptor[]{pageHelper});
return pageHelper;
}
controller中使用
@RequestMapping("/getAllShare")
public PageInfo get(@RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum){
PageHelper.startPage(pageNum, 3);
List<Share> shareList = shareService.getAllShare();
PageInfo<Share> pageInfo = new PageInfo<>(shareList);
return pageInfo;
}