pagehelper 不分页几种情况的解决方法
近期做一個(gè)項(xiàng)目,用到了該插件,遇到了些問題,在這里分享一下解決方法
問題一:
pagehelper沒有效果,一直不能分頁問題
解決方法-引用其他博主的博客的解決:http://blog.csdn.net/linxingliang/article/details/52566881
問題二:
pagehelper有的時(shí)候有效果,有時(shí)候沒有效果
解決方法1:
pagehelper里面的
PageHelper.startPage(1,10);只對該語句以后的第一個(gè)查詢語句得到的數(shù)據(jù)進(jìn)行分頁
就算你在PageInfo pa = new PageInfo("",對象);語句里面的對象是寫的最終得到的數(shù)據(jù),該插件還是只會(huì)對第一個(gè)查詢所查詢出來的數(shù)據(jù)進(jìn)行分頁
第一個(gè)查詢語句是指什么呢?舉個(gè)例子吧,比如你有一個(gè)查詢數(shù)據(jù)的方法,寫在了PageHelper.startPage(1, 10);下面.但是這個(gè)查詢方法里面
包含兩個(gè)查詢語句的話,該插件就只會(huì)對第一查詢語句查詢的數(shù)據(jù)進(jìn)行分頁,而不是對返回最終數(shù)據(jù)的查詢與基礎(chǔ)查詢出來的數(shù)據(jù)進(jìn)行分頁
改變一下自己的代碼結(jié)構(gòu),讓最終需要的數(shù)據(jù)所需要的查詢語句放在PageHelper.startPage(1, 10)下面就行,如:
String tenantId = wpBaseInfoService.queryTenantId(record.getChargeWork()); record.setTenantCode(tenantId); PageHelper.startPage(pageNum, pageSize); List<WpBaseInfo> list = wpBaseInfoService.selectWpListForward(record);解決方法2:
#pagehelper pagehelper: helperDialect: oraclereasonable: false//這個(gè)熟悉需要改成falsesupportMethodsArguments: trueparams: count=countSql @RequestMapping("loc/list")@ResponseBodypublic Map<String, Object> locList(QueryRequest request, Loc loc) { // PageHelper.startPage(request.getPageNum(), request.getPageSize()); // List<Loc> list = this.locService.findAllLoc(loc);HashMap<String,Object> map = new HashMap<String,Object>();List<String> schemas = this.locMapper.findAllSchema(loc);map.put("schemas", schemas);map.put("loc", loc);PageHelper.startPage(request.getPageNum(), request.getPageSize());//PageHelper只對緊跟著的第一條SQL起作用List<Loc> list = this.locMapper.findAllLoc(map);//這條語句被視為緊跟著的第一條語句PageInfo<Loc> pageInfo = new PageInfo<>(list);return getDataTable(pageInfo);}總結(jié)
以上是生活随笔為你收集整理的pagehelper 不分页几种情况的解决方法的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 04 | 深入浅出索引(上)
- 下一篇: springboot 配置资源映射路径