返回数据格式为
{
code: "S000"
data: {
rows: [ ], // 分页数据
total: 17 // 数据总条数,前端用于处理展示页码
}
message: "ok"
}
查询代码
分为两次查询,一次查询分页数据,一次查询总页数
router.get('/list', function (req, res, next) {
let params = {};
params.page = Number(req.query.page) || 1;
params.pageSize = Number(req.query.pageSize) || 10;
let pageSize = params.pageSize;
let page = (params.page - 1) * pageSize;
let sql =
`
SELECT date,id,phone,name,ipaddr,domain,des,useragent,mark from icp_log limit ?,?;
`;
let flag = req.query.flag;
database.query(sql, [page, pageSize], (err, rows, fileds) => {
if (err) {
throw err;
}
let sql = `SELECT COUNT(id) as total FROM icp_log;`
database.query(sql, [], (err, rows1, fileds) => {
let total = rows1[0]['total']
res.json({ message: "ok", data: {
rows,
total
}, code: 'S000' });
})
})
});
网友评论