PageHelper只对紧跟着的第一条SQL起作用

这个sql的中心思想就是根据查询到的schema然后分别查询schema中的相关数据再用union all将结果及拼接在一起。
LocServiceImpl.findAllLoc(Loc loc)
@Override
    public List<Loc> findAllLoc(Loc loc) {
        try {
            HashMap<String,Object> map = new HashMap<String,Object>();
            List<String> schemas = this.locMapper.findAllSchema(loc);//查询所有的schema
            map.put("schemas", schemas);
            map.put("loc", loc);
            return this.locMapper.findAllLoc(map);
        } catch (Exception e) {
            e.printStackTrace();
            return new ArrayList<>();
        }
    }

//分页异常的代码的LocController中代码

@RequestMapping("loc/list")
    @ResponseBody
    public Map<String, Object> locList(QueryRequest request, Loc loc) {
        PageHelper.startPage(request.getPageNum(), request.getPageSize());
        List<Loc> list = this.locService.findAllLoc(loc);//具体实现在第一段代码。系统认为findAllSchema(loc)是第一条语句。PageHelper只对紧跟着的第一条SQL起作用

//        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());
//        List<Loc> list =  this.locMapper.findAllLoc(map);
        
        PageInfo<Loc> pageInfo = new PageInfo<>(list);
        return getDataTable(pageInfo);
    }

//yml配置

#pagehelper
pagehelper: 
  helperDialect: oracle
  reasonable: false//这个熟悉需要改成false
  supportMethodsArguments: true
  params: count=countSql 

 //分页正常的LocController中代码,拆分开,然后把PageHelper放在需要分页的SQL之前,就正常了。

@RequestMapping("loc/list")
    @ResponseBody
    public 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);
    }
原文地址:https://www.cnblogs.com/CryOnMyShoulder/p/11428476.html