- nodejs 服务端,获取参数的4中方法,req.body,req.query,req.params,req.param()
Req.body 用于post
Req.query 用于 http://localhost:3000?id=1&name=3
Req.params 用于 http://localhost:3000/:name/:id pathparam
app.get("/testpath/:name",function(req,res){
console.log("req.params",req.params); //这个用于url有参数的情况
http://localhost:3000/:name/:id
java中是http://localhost:3000/{name}/{id}
console.log("req.body()",req.body); //这个一般用于post请求
req.body.name
req.body.id
console.log("req.query",req.query)
req.query.id
req.quer.name
http://localhost:3000?id=1&name=zhangsan
console.log("req.param('name')",req.param('name'));//这个方法已经被丢弃了
res.send("aaaaaaaa");
})