其實pagehelper用着一直沒什么問題,分頁正常
直到和前端同事測試時,說我的total返回的是pageSize而不是總記錄數
PageHelper.startPage(pageNum,pageSize); // JSONObject data=JSONObject.parseObject(this.studentService.query(json).toJSONString()); // List<Student> list= JSONArray.parseArray(data.getString("studentList"), Student.class);
List<Student> list=this.studentService.query(json); PageInfo<List> pageInfo = new PageInfo(list);
一開始我是注釋里的寫法,pageSize傳進來 5,total是5
后來查了下網上,總結就是
startPage后面只能像這樣單釣一個查詢,其他寫法都會有問題,雖然數據分頁可以成功
我之前查詢封裝成json沒改,在分頁獲取數據也只是先get到再分頁,所以total和pagesize一樣
之后第二個問題也來了,數據獲取為空,看控制台
Field studentService in com.lzhl.liziweixiao.controller.IndexController required a bean of type 'com.lzhl.liziweixiao.service.IStudentService' that could not be found
Consider defining a bean of type 'com.lzhl.liziweixiao.service.IStudentService' in your configuration.
但獲取數據時改成以下形式就可以了
List<Student> list=this.studentMapper.query(name,clazz,number); return list;
雖然后來改成return this.mapper.query也沒問題,但還是會報上面的提示,暫時未明確原因,以后再補充,以上思路以供參考