This commit is contained in:
2019-12-10 14:32:04 +08:00
parent 15fd23bee2
commit 63e6bb971f
7 changed files with 793 additions and 0 deletions

46
controllers/index.js Normal file
View File

@@ -0,0 +1,46 @@
// 获取标签
var getlist = async (ctx, next) => {
await dbs.find('list').then((res) => {
ctx.body = JSON.stringify(res)
})
next()
}
var addlist = async (ctx,next) =>{
if(ctx.request.body.name == undefined || ctx.request.body.age == undefined){
ctx.body = JSON.stringify({
code:1,
msg:"姓名或年龄不能为空"
})
}else{
await dbs.add('list',{
name:ctx.request.body.name,
age:ctx.request.body.age
}).then((res)=>{
ctx.body = JSON.stringify(res)
})
}
next()
}
var getaddlist = async (ctx,next) =>{
if(ctx.query.name == undefined || ctx.query.age == undefined){
ctx.body = JSON.stringify({
code:1,
msg:"姓名或年龄不能为空"
})
}else{
await dbs.add('list',{
name:ctx.query.name,
age:ctx.query.age
}).then((res)=>{
ctx.body = JSON.stringify(res)
})
}
next()
}
module.exports = {
'GET /getlist':getlist,
'POST /addlist':addlist,
'GET /getaddlist':getaddlist
}