# 查询分页
分页是用到比较多的模块,如想实现分页,需加selectForPage然后传args.getPageParams()接收参数,系统会自动解析生成分页,并返回总页数,当前页数,总条数,列表模块数据。当然也可以不加selectForPage或不加select方法,只相当于传sql语句;下面是示例,一起看下吧!
分页查询示例
```java
Page<RowData> rowData = Db.name("tg_task").where("status", 1).selectForPage(args.getPageParams());
或
Query<RowData> rowData = Db.name("tg_task").where("status", 1);
```
分页遍历示例
```java
Page<RowData> rowData = Db.name("tg_task").where("status", 1).rowDataCallback(new RowDataCallback<RowData, Integer>() {
@Override
public void onData(RowData data, Integer index) {
data.set("abc", 123);
}
}).selectForPage(args.getPageParams());
或
Query<RowData> rowData = Db.name("tg_task").where("status", 1).rowDataCallback(new RowDataCallback<RowData, Integer>() {
@Override
public void onData(RowData data, Integer index) {
data.set("abc",123);
}
});
```
运行结果
```java
{
"code": 1,
"msg": "success",
"data": {
"total": 2,
"pageSize": 100,
"page": 1,
"pageTotalNum": 1,
"rows": [
{
"abc": 123,
"end_time": "1628352000",
"remark": "",
"title": "李白的【2021-08-06到2021-08-08】工作任务",
"addtime": "1628219679"
},
{
"abc": 123,
"end_time": "1628352000",
"remark": "",
"title": "2222",
"addtime": "1628239735"
}
]
}
}
```