pagehelper-org/Mybatis-PageHelper · error · PageException
pagination parameters are not a valid number type!
Error message
pagination parameters are not a valid number type!
What it means
PageHelper read the pageNum/pageSize values from the parameter object but could not parse them into integers — Integer.parseInt failed with NumberFormatException, which is wrapped in a PageException. The paging parameters exist but are not valid number types (e.g. "abc", "12.5", or a non-numeric object).
Solutions
- Validate/sanitize pageNum and pageSize before calling the paging API (parse with NumberUtils and fall back to defaults)
- Ensure values are whole numbers: trim strings, reject/round decimals, and empty-check before paging
- If values come from HTTP, bind them as Integer in the DTO so the framework fails fast with a clean 400
- Wrap the paging call in try-catch for PageException and degrade to default paging instead of failing the request
Example fix
// before
params.put("pageNum", request.getParameter("page")); // may be "abc"
PageHelper.startPage(params);
// after
int pageNum = NumberUtils.toInt(request.getParameter("page"), 1);
int pageSize = NumberUtils.toInt(request.getParameter("size"), 10);
PageHelper.startPage(pageNum, pageSize); Defensive patterns
Strategy: validation
Validate before calling
Object pn = map.get("pageNum"), ps = map.get("pageSize");
if (pn == null || ps == null
|| !pn.toString().matches("\\d+")
|| !ps.toString().matches("\\d+")) {
throw new IllegalArgumentException("pageNum/pageSize must be positive integers");
}
PageHelper.startPage(map); Try / catch
try {
PageHelper.startPage(params);
} catch (PageException e) {
log.warn("invalid paging numbers, using defaults: {}", e.getMessage());
PageHelper.startPage(1, 10);
} Prevention
- Bind HTTP paging params as Integer fields in DTOs, not String
- Reject decimals/empty strings at the API boundary with 400 responses
- Use NumberUtils.toInt(value, default) for tolerant parsing before paging
When it happens
Trigger: Passing pageNum="abc" or pageSize="3.5" in a Map used for paging; passing a non-numeric Object (e.g. a Locale or array) under the _pageNum/_pageSize keys; HTTP query params bound as raw strings with typos or empty strings placed into the paging map.
Common situations: Spring binds request parameters as Strings and a user supplies page=two; frontend sends pageSize=10.0 from JS floats; a config file supplies non-numeric defaults; a JSON deserializer yields Doubles with decimal points that fail parseInt.
Understand the failure class
Background: "Invalid ... format", "must be in format X", "does not look like a ..." — invalid argument format errors across CLI tools and libraries — this error's family across 17 libraries.
Related errors
- unable to get paginated query parameters!
- The pagination query parameter failed to be processed!
- Paginated queries are missing the necessary parameters
- When you use the PageHelper pagination plugin, you must set…
- Make sure the Dialect implementation class configured by…
AI-assisted analysis of pagehelper-org/Mybatis-PageHelper@c692616c5b (2026-09-08).
Data as JSON: /api/errors/2c1a132e339baa55.
Report an issue: GitHub.
Appendix: source
Thrown at src/main/java/com/github/pagehelper/util/PageObjectUtil.java:126
if (orderBy != null && orderBy.toString().length() > 0) {
hasOrderBy = true;
}
try {
Object _pageNum = getParamValue(paramsObject, "pageNum", required);
Object _pageSize = getParamValue(paramsObject, "pageSize", required);
if (_pageNum == null || _pageSize == null) {
if(hasOrderBy){
Page page = new Page();
page.setOrderBy(orderBy.toString());
page.setOrderByOnly(true);
return page;
}
return null;
}
pageNum = Integer.parseInt(String.valueOf(_pageNum));
pageSize = Integer.parseInt(String.valueOf(_pageSize));
} catch (NumberFormatException e) {
throw new PageException("pagination parameters are not a valid number type!", e);
}
Page page = new Page(pageNum, pageSize);
//count查询
Object _count = getParamValue(paramsObject, "count", false);
if (_count != null) {
page.setCount(Boolean.valueOf(String.valueOf(_count)));
}
//排序
if (hasOrderBy) {
page.setOrderBy(orderBy.toString());
}
//分页合理化
Object reasonable = getParamValue(paramsObject, "reasonable", false);
if (reasonable != null) {
page.setReasonable(Boolean.valueOf(String.valueOf(reasonable)));
}
//查询全部
Object pageSizeZero = getParamValue(paramsObject, "pageSizeZero", false);View on GitHub (pinned to c692616c5b)