ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
[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; }); ~~~