完成
This commit is contained in:
46
controllers/index.js
Normal file
46
controllers/index.js
Normal 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
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user