连接mysql数据库
module.exports = {
add:function(req,res,next){
pool.getConnection(function(err,connection){
if(err){
//...
}
//获取前台传来的参数
var param = req.query||req.params
console.log(req.query.name) //TypeError
//数据库插入操作
})
}
}
问题:
直接修改URL为:http://127.0.0.1:3000/users/a... ,打印 param 为undefined
并且报错
Cannot read property 'name' of undefined
已解决
上述代码没有任何问题,是路由跳转的问题,以下为错误代码
req 和 res 顺序错了,the request (req) should be the
first
argument,希望只有我一个人犯了这样的错误T.T