gpt4 book ai didi

Node.js:req.query[] 和 req.params 之间的区别

转载 作者:IT老高 更新时间:2023-10-28 21:47:45 28 4
gpt4 key购买 nike

通过 req.query[myParam]req.params.myParam 获取 QUERY_STRING 参数有区别吗?如果是这样,我应该什么时候使用哪个?

最佳答案

鉴于这条路线

app.get('/hi/:param1', function(req,res){} );
// regex version
app.get(/^\/hi\/(.*)$/, function(req,res){} );
// unnamed wild card
app.get('/hi/*', function(req,res){} );

并给出这个 URLhttp://www.google.com/hi/there?qs1=you&qs2=tube

你将拥有:

req.查询

{
qs1: 'you',
qs2: 'tube'
}

req.参数

{
param1: 'there'
}

When you use a regular expression for the route definition, capture groups are provided in the array using req.params[n], where n is the nth capture group. This rule is applied to unnamed wild card matches with string routes

Express req.params >>

关于Node.js:req.query[] 和 req.params 之间的区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14417592/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com