pagehelper-org/Mybatis-PageHelper · error · PageException

unable to get paginated query parameters!

Error message

unable to get paginated query parameters!

What it means

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.

Solutions

  1. Ensure a non-null parameter object is built before calling the paging API (e.g. new HashMap<>() or the request DTO instance)
  2. Guard the call site: only invoke paging when params != null, otherwise use a default Page
  3. Switch to the explicit startPage(int pageNum, int pageSize) overload which does not accept null
  4. Check which code path calls PageObjectUtil.getPageFromObject and add null handling/logging there

Example fix

// before
PageHelper.startPage(params);
// after
if (params == null) {
    params = new HashMap<>(); // or defaults: pageNum=1, pageSize=10
}
PageHelper.startPage(params);
Defensive patterns

Strategy: validation

Validate before calling

if (params == null) {
    throw new IllegalArgumentException("paging params must not be null");
}
PageHelper.startPage(params);

Type guard

boolean isPagingParams(Object p) {
    return p != null && (p instanceof Map || p instanceof IPage);
}

Try / catch

try {
    PageHelper.startPage(params);
} catch (PageException e) {
    log.warn("paging skipped: {}", e.getMessage());
    // proceed un-paged or with defaults
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of pagehelper-org/Mybatis-PageHelper@c692616c5b (2026-09-08). Data as JSON: /api/errors/4708c45f080aa9e9. Report an issue: GitHub.

Appendix: source

Thrown at src/main/java/com/github/pagehelper/util/PageObjectUtil.java:72

            hasRequest = false;
        }
        PARAMS.put("pageNum", "pageNum");
        PARAMS.put("pageSize", "pageSize");
        PARAMS.put("count", "countSql");
        PARAMS.put("orderBy", "orderBy");
        PARAMS.put("reasonable", "reasonable");
        PARAMS.put("pageSizeZero", "pageSizeZero");
    }

    /**
     * 对象中获取分页参数
     *
     * @param params
     * @return
     */
    public static <T> Page<T> getPageFromObject(Object params, boolean required) {
        if (params == null) {
            throw new PageException("unable to get paginated query parameters!");
        }
        if(params instanceof IPage){
            IPage pageParams = (IPage) params;
            Page page = null;
            if(pageParams.getPageNum() != null && pageParams.getPageSize() != null){
                page = new Page(pageParams.getPageNum(), pageParams.getPageSize());
            }
            if (StringUtil.isNotEmpty(pageParams.getOrderBy())) {
                if(page != null){
                    page.setOrderBy(pageParams.getOrderBy());
                } else {
                    page = new Page();
                    page.setOrderBy(pageParams.getOrderBy());
                    page.setOrderByOnly(true);
                }
            }
            return page;
        }

View on GitHub (pinned to c692616c5b)