NIUCLOUD是一款SaaS管理后台框架多应用插件+云编译。上千名开发者、服务商正在积极拥抱开发者生态。欢迎开发者们免费入驻。一起助力发展! 广告
[TOC] ### limt 分页查询 ### 查询前3条记录 分页公式: ![](https://box.kancloud.cn/852300f18e10cb79f2c39a5b855308df_570x160.png) `(offset - 1) * limit` ~~~ SELECT name FROM `student` LIMIT 0, 3; Student.findAll( { attributes:['name'], // 当前页 offset:0, // 每页显示的条数 limit:3 }) ~~~ ***** ### 分页案例 ~~~ router.get('/getUserList', async (ctx, next) => { let { currentPage=1, count=10 } = ctx.request.header; const userList = await models.user.findAllAndCount({ limit: parseInt( count ), offset:(currentPage - 1) * count, include: [{ model: { explore }, as: 'order_info' }], distinct: true }).then(res => { let result = {}; result.data = res.rows; result.totalCount = res.count; return result; }); ctx.body = userList; }); ~~~