我想做一些事情,我想用Mysql/Node.JS / Express.JS在两个日期之间搜索,这里是什么?我不知道如何使用app.get()向Node.JS应用程序传递2个参数
例如,我有这个
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
})如何使用两个参数获取日期?
发布于 2021-11-19 03:42:37
您有不同的选项,可以使用查询字符串,如下所示
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,并按预期提取它。
发布于 2021-11-19 01:13:55
您可以在一个单独的字符串中发送数据,但是在中间插入一个特殊值(*%$),然后在代码中用前面用来创建包含您的值的数组的特殊值来拆分字符串。
https://stackoverflow.com/questions/70025675
复制相似问题