使用PageHelper插件进行分页
1.pom.xml中加入
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper</artifactId>
<version>4.1.6</version>
</dependency>
2.mybatis-config.xml中加入,版本是5.几以上的话 <property name="dialect" value="mysql"/>
就可以不用写了
<plugin interceptor="com.github.pagehelper.PageHelper">
<property name="dialect" value="mysql"/>
</plugin>
3,关键地方来了。分页代码,pageNum是当前第几页,pagesSize是每页分多少,数据库一个全查就行了,不需要写limit分页查询语句
@RequestMapping(value="/alladv",method = RequestMethod.POST)
@ResponseBody
public PageInfo<News> getAllAdvertis(int pageNum,Integer pageSize){
Map<String, Object> result=new HashMap<>();
PageHelper.startPage(pageNum , pageSize);
List<News> list=newsService.getAllAdv();
PageInfo<News> pageInfo=new PageInfo<>(list);
List<News> list1=pageInfo.getList();
result.put("pageInfo", list1);
return pageInfo;
}