English | 简体中文
GORM paginate plugin(program implementation for)
-
Paging
page
: current page (default 1)size
: number of records per page (default 10)
-
Sorting
order_by
: sort field and direction (e.g.created_at desc, name
)
-
Filtering conditions
- Format:
<field>_<operator>=<value>
.- E.g.
age_gt=20
(where age > 20),name_like=John%
(where LIKE 'John%')
- E.g.
- Supported comparisons
eq
equals (default)ne
is not equal togt
greater thangte
greater than equalslt
less thanlte
less than equalsbetween
Range searchlike
fuzzy matchnotlike
non-fuzzy matchis
isnot
in
- Format:
- Simple paging and sorting
GET http://localhost:8080/users?size=10&page=0&order_by=-name,id
- Equivalent SQL
SELECT * FROM users ORDER BY name DESC, id ASC LIMIT 10 OFFSET 0
- JSON Response:
{
"page": 1,
"size": 10,
"order_bys": [
{
"field": "name",
"direction": "desc"
},
{
"field": "id",
"direction": "asc"
}
],
"wheres": [],
"comments": [],
"items": [
{
"ID": 29,
"CreatedAt": "2025-03-23T16:12:58.166418+08:00",
"UpdatedAt": "2025-03-23T16:12:58.166418+08:00",
"DeletedAt": null,
"Name": "zxpet",
"Age": 38,
"Balance": 28,
"AccountManager": "bbc"
},
...
],
"total": 200,
"total_pages": 20
}
- Conditional Search
GET http://localhost:8080/users?size=10&page=1&age_gt=16&name_like=e%&balance_between=20,250&account_manager_in=zhangsi,lisi
- Equivalent SQL
SELECT * FROM users WHERE age > 16 AND name LIKE "e%" and balance BETWEEN 20 AND 250 and account_manager in ("zhangsan", "lisi") LIMIT 10 OFFSET 0
- JSON Response:
{
"page": 1,
"size": 10,
"order_bys": [],
"wheres": [
{
"field": "account_manager",
"operator": "in",
"value": [
"zhangsi",
"lisi"
]
},
{
"field": "age",
"operator": "gt",
"value": "16"
},
{
"field": "name",
"operator": "like",
"value": "e%"
}
],
"comments": [
"invalid operator: between for field: balance"
],
"items": [
{
"ID": 113,
"CreatedAt": "2025-03-23T17:11:45.97259+08:00",
"UpdatedAt": "2025-03-23T17:11:45.97259+08:00",
"DeletedAt": null,
"Name": "etiax",
"Age": 22,
"Balance": 12,
"AccountManager": "zhangsi"
}
],
"total": 200,
"total_pages": 20
}
© xiexianbin, 2025~time.Now
Released under the Apache License