//使用pager进行分页展示 //首先Service层的书写,例如: ServerResponse<Pager> selectUserAll(int curentPageIndex,int countPerpage); //Impl实现层的书写,例如: public ServerResponse<Pager> selectUserAll(int curentPageIndex,int countPerpage) { UserExample example = new UserExample(); UserExample.Criteria criteria = example.createCriteria();
List<User> users = userMapper.selectByExample(example); Pager pager=new Pager();//创建pager对象 if(users.size()>0){//判断是否含有数据 pager.setBigList(users);//把list对象放入pager中大的集合 pager.setCurentPageIndex(curentPageIndex);//设置pager当前页 pager.setCountPerpage(countPerpage);//设置pager一页含有总数 ServerResponse serverResponse=ServerResponse.createBySuccess(pager.getSmallList(),"查询成功",users.size());//这里传给serverResponse的是 //pager中的小集合。 return serverResponse; }else { return ServerResponse.createByErrorMessage("查询失败"); } } //controller层: public ServerResponse<Pager> fingdAllUser( @RequestParam(value = "curentPageIndex", defaultValue = "1") int curentPageIndex, @RequestParam(value = "countPerpage", defaultValue = "10") int countPerpage) { return testService.selectUserAll(countPerpage, curentPageIndex); }