{"record":{"id":"4708c45f080aa9e9","repo":"pagehelper-org/Mybatis-PageHelper","slug":"unable-to-get-paginated-query-parameters","errorCode":null,"errorMessage":"unable to get paginated query parameters!","messagePattern":"unable to get paginated query parameters!","errorType":"exception","errorClass":"PageException","httpStatus":null,"severity":"error","filePath":"src/main/java/com/github/pagehelper/util/PageObjectUtil.java","lineNumber":72,"sourceCode":"            hasRequest = false;\n        }\n        PARAMS.put(\"pageNum\", \"pageNum\");\n        PARAMS.put(\"pageSize\", \"pageSize\");\n        PARAMS.put(\"count\", \"countSql\");\n        PARAMS.put(\"orderBy\", \"orderBy\");\n        PARAMS.put(\"reasonable\", \"reasonable\");\n        PARAMS.put(\"pageSizeZero\", \"pageSizeZero\");\n    }\n\n    /**\n     * 对象中获取分页参数\n     *\n     * @param params\n     * @return\n     */\n    public static <T> Page<T> getPageFromObject(Object params, boolean required) {\n        if (params == null) {\n            throw new PageException(\"unable to get paginated query parameters!\");\n        }\n        if(params instanceof IPage){\n            IPage pageParams = (IPage) params;\n            Page page = null;\n            if(pageParams.getPageNum() != null && pageParams.getPageSize() != null){\n                page = new Page(pageParams.getPageNum(), pageParams.getPageSize());\n            }\n            if (StringUtil.isNotEmpty(pageParams.getOrderBy())) {\n                if(page != null){\n                    page.setOrderBy(pageParams.getOrderBy());\n                } else {\n                    page = new Page();\n                    page.setOrderBy(pageParams.getOrderBy());\n                    page.setOrderByOnly(true);\n                }\n            }\n            return page;\n        }","sourceCodeStart":54,"sourceCodeEnd":90,"githubUrl":"https://github.com/pagehelper-org/Mybatis-PageHelper/blob/c692616c5bc95b41aa779b502f991825c8e5acbc/src/main/java/com/github/pagehelper/util/PageObjectUtil.java#L54-L90","documentation":"PageHelper's getPageFromObject was called with a null params object, so it cannot derive pagination (pageNum/pageSize) at all. The library throws PageException immediately because there is nothing to read pagination values from. This typically happens when the caller passes null to PageHelper.startPage(...) indirectly via a Map or object parameter.","triggerScenarios":"Calling PageHelper.startPage via parameter-object overloads (e.g. startPage(Object params) or paging through a Map) with a null argument; a service passes a request DTO that is null down to the paging helper; framework binding produces null before getPageFromObject is invoked.","commonSituations":"Controller receives no paging params and the assembled Map is null; MyBatis mapper called with a single null parameter while an OrderBy/paging plugin variant expects a parameter object; refactoring changed startPage(pageNum,pageSize) to the params-object overload without null checks.","solutions":["Ensure a non-null parameter object is built before calling the paging API (e.g. new HashMap<>() or the request DTO instance)","Guard the call site: only invoke paging when params != null, otherwise use a default Page","Switch to the explicit startPage(int pageNum, int pageSize) overload which does not accept null","Check which code path calls PageObjectUtil.getPageFromObject and add null handling/logging there"],"exampleFix":"// before\nPageHelper.startPage(params);\n// after\nif (params == null) {\n    params = new HashMap<>(); // or defaults: pageNum=1, pageSize=10\n}\nPageHelper.startPage(params);","handlingStrategy":"validation","validationCode":"if (params == null) {\n    throw new IllegalArgumentException(\"paging params must not be null\");\n}\nPageHelper.startPage(params);","typeGuard":"boolean isPagingParams(Object p) {\n    return p != null && (p instanceof Map || p instanceof IPage);\n}","tryCatchPattern":"try {\n    PageHelper.startPage(params);\n} catch (PageException e) {\n    log.warn(\"paging skipped: {}\", e.getMessage());\n    // proceed un-paged or with defaults\n}","preventionTips":["Never pass a possibly-null DTO/Map into the params-object paging overload","Prefer explicit startPage(pageNum, pageSize) over the object overload when values are known","Default paging values at the controller boundary"],"tags":["pagination","null-argument","mybatis","pagehelper"],"backgroundTag":"null-argument","analyzedSha":"c692616c5bc95b41aa779b502f991825c8e5acbc","analyzedAt":"2026-09-08T03:50:49.192Z","contentChangedAt":"2026-09-08T03:50:49.192Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}