我需要发布数据(例如数组),但我总是这样发送数据:
{
"books": [
{
"id": 19,
"name": "Král Lávra",
"author": "Karel Havlíček Borovský",
"yearOfRelease": "1920",
"price": "120",
"SubjectId": 1,
"UserId": 2,
"SchoolId": 1
},
]
}
我想要这样显示结果:
[
{
"id": 19,
"name": "Král Lávra",
"author": "Karel Havlíček Borovský",
"yearOfRelease": "1920",
"price": "120",
"SubjectId": 1,
"UserId": 2,
"SchoolId": 1
},
]
我使用sequelize连接数据库MySQL。这是我的findAll书的代码:
let books = await ctx.db.Book.findAll({
where: {
UserId: id
},
})
然后我只发布到
ctx.body= {
books
}
感谢您的回复。