URL匹配与req参数解析

通配URL*(可代表任何字符串)

例如:

app.get('/test/*', function(req, res){

  res.send(req.query.aa);

})

'/test/*通配test/...的URL

占位符URL(匹配一级)

例如:

app.get('/test/:a', function(req, res){

  res.send(req.query.aa);

})

'/test/*匹配test/a, test/b等的URL不匹配test/a/b

req参数获取:

req.query 处理get请求

req.params 处理/:xxx形式的get请求

req.body 处理post请求

req.param() 可以处理get和post请求,查找优先级为req.params-->req.body-->req.query

原文地址:https://www.cnblogs.com/yanze/p/6089713.html