在express.js的controllers里我们经常看到request.query,
request.params, request.body,这些都是什么意思呢?跟我们用来作请求的url形式有什么关联呢?
https://stackoverflow.com/questions/39175587/request-body-vs-request-params-vs-request-query
req.params is route parameters, req.body is the actual body of the request, and req.query is any query parameters.
For example, if I declare this route:
以这个请求为例
router.get('/user/:id',function(req,res){});
request.params will contain id.
If I pass a body to this route:
{name:'josh'}
This will be in request.body.
If I pass some query parameters to http://myserver.com/api/user?name="josh", request.query will be { name: 'josh' }.
?后面带的参数就是request.query
Check out the Express docs.
网友评论