下面是具体代码
async index() {
// 拿到数据
let result = {};
let Op = this.app.Sequelize.Op;
let page = this.ctx.query.page ? parseInt(this.ctx.query.page) : 1;
let limit = 5;
let offset = (page-1)*5;
// 查询多个
result = await this.app.model.User.findAll({
// where:{
// sex:'男',
// username:{
// [Op.like]:"%张三%"
// },
// id:{
// [Op.gt]:6
// }
// },
// 限制查询字段
// attributes:['id','username','sex']
attributes:{
// 排除
exclude:['password']
},
// 排序
order:[
// id 降序
['updated_at','DESC'],
['id','DESC']
],
// 这里由于参数是offset,所以我们省略,offset:offset 等同于 offset,
offset,
// 分页
limit
});
// 查询多个并统计
// result = await this.app.model.User.findAndCountAll();
this.ctx.body = {
msg:'ok',
data:result
}
}
这是查询的数据
感谢大家观看,我们下次见