1)req.query (查詢get請求中的參數)
GET /shoes?order=desc&shoe[type]=converse&shoe[color]=blue req.query.order // =>'desc' req,query.shoe.type // =>'converse'
(2)req.body (查詢post請求體)
// POST user[name]=dby&user[email]=bing@163.com req.body.user.name // =>'dby'
(3)req.params
// GET /file/javascript/jquery.js req.params[0] // => 'javascript/jquery.js'
(4)req.params(name)
// ?name=tobi req.params(name) // => 'tobi' // POST name=tobi req.param('name') // => 'tobi'//歡迎加入前端全棧開發交流圈一起學習交流:864305860
由上述代碼可以很明顯的看出各種獲取路徑的含義:
req.query: 處理get請求,獲取get請求的請求參數
req.params: 處理/:xxx形式的get或者post請求,獲取請求參數
req.body: 處理post請求,獲取post了請求的請求體
req.param(): 處理get和post請求,但查找優先級由高到低為req.params->req.body->req.query
注:路徑規則支持正則表達式。
req.query: 處理get請求,獲取get請求的請求參數
req.params: 處理/:xxx形式的get或者post請求,獲取請求參數
req.body: 處理post請求,獲取post了請求的請求體
req.param(): 處理get和post請求,但查找優先級由高到低為req.params->req.body->req.query
注:路徑規則支持正則表達式。
作者:前端攻城小牛
鏈接:https://www.jianshu.com/p/e9d8d44575cb
來源:簡書
著作權歸作者所有。商業轉載請聯系作者獲得授權,非商業轉載請注明出處。