我想做點什么,我想使用 Mysql/Node.JS/Express.JS 在兩個日期之間進行搜索 這是什么?我不知道如何將 2 個引數傳遞給 Node.JS 應用程式app.get()
例如,我有這個
app.get('/api/v1/listcustomers/:subscription_id',function(req,res){
//Rest of SQL query goes here
})
現在這是一個引數,它使用一個引數獲取資料,我想使用兩個引數獲取日期,我如何在 Node.JS 中執行此操作
使用這個 app.get('/api/v1/trans_details/:date_from',function(req,res))
所以通過編碼它應該是這樣的:
app.get('/api/v1/trans_details/:date_from',function(req,res){
rest of code goes here, to get data using 2 parameter
})
如何使用 2 個引數獲取日期?
uj5u.com熱心網友回復:
您有不同的選擇,您可以使用查詢字串,如
app.get('/api/v1/trans_details',function(req,res){
const { from, to } = req.query;
})
你會稱它為
/api/v1/trans_details?from=2021-01-01&to=2021-12-31
或者如果你想把它作為你可以做的 url 的部分,那么值將在req.params而不是req.query
app.get('/api/v1/trans_details/:from/:to',function(req,res){
const { from, to } = req.params;
})
你會稱它為
/api/v1/trans_details/2021-01-01/2021-12-31
具有與 url 匹配的模式的 express 并按預期提取它
uj5u.com熱心網友回復:
您可以在單個字串中發送資料,但在中間插入一個特殊值 (*%$),然后在代碼中將字串按您之前使用的特殊值拆分,以使用您的值創建陣列。
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/360650.html
