我的查询代码如下:
@Override
public Map<String, Object> findArticlePage(Integer page, Integer limit, ArticleAllVo articleAllVo) {
PageHelper.startPage(page, limit); //通用分页拦截器,参数为分别为当前页、每页记录数
Page<ArticleAllVo> articles = articleAllDao.findArticlePage(articleAllVo);
System.out.println(articles.getTotal());
System.out.println(articles.getResult());
return ResultUtil.put(ConstantUtil.REQUEST_SUCCESS, articles.getTotal(), "", articles.getResult());
}
正常的查询接口如下:
而我的查询接口如下
查找了网上的资料后,发现是自己的配置出问题了,于是在spring-mybatis.xml文件中添加了如下代码:
<!-- 配置mybatis分页插件PageHelper -->
<property name="plugins">
<array>
<bean class="com.github.pagehelper.PageInterceptor">
<property name="properties">
<!-- 什么都不配,使用默认的配置 -->
<value></value>
</property>
</bean>
</array>
</property>
但是这段代码的位置放在哪里呢,如下图所示:
controller层的代码,这里查询条件是写死的,还没有实现从前台传查询条件
@RequestMapping(value = "/getallarticleinfo")
public @ResponseBody Map<String, Object> getAllArticleInfo(HttpSession session,Integer page, Integer limit,SearchInfo searchInfo2) {
SearchInfo searchInfo = new SearchInfo();
//UserVo user = (UserVo) session.getAttribute("user");
UserVo user = new UserVo();
user.setId(1);
user.setUserRight(1);
searchInfo.setPageId(1);
searchInfo.setSearchInfo("我");
searchInfo.setUser(user);
ArticleAllVo articleAllVo = new ArticleAllVo();
articleAllVo.setArticleTitle("");
Map<String, Object> map = articleAllService.findArticlePage(page, limit, articleAllVo);
return map;
}
好了,分页的实现大功告成