router.get('/userinfo', (req, res) => {
var start = (req.query.page - 1) * 10;
//page是传过来的页数(page-1乘以10就是起始行)
var sql = 'SELECT COUNT(*) FROM userinfo; SELECT * FROM userinfo limit ' + start + ',10';
//COUNT(*) 函数返回在给定的选择中被选的行数。 //检索记录行,从start以后10行
conn.query(sql,function (err, results) {
if(err){
res.json({ code: -200, message: err})
return;
}
var allCount = results[0][0]['COUNT(*)'];
var allPage = parseInt(allCount)/10;
var pageStr = allPage.toString();
if (pageStr.indexOf('.')>0) {
allPage = parseInt(pageStr.split('.')[0]) + 1;
}
var List = results[1];
res.json({code:200,data:List,totalPages:allPage})
});
})
网友评论