繁体   English   中英

当我的 sql 查询必须从表中选择两个元素时,如何在 rest api 上的 app.get 函数中调整路径?

[英]How to right the path in app.get function on rest api when my sql query has to select by two elements from the table?

我在开发 android 应用程序方面很新,我正在尝试使用 rest api 对我的应用程序进行身份验证,但我无法在我的函数“app.get”上找到正确的路径

app.get('/getPatient2/:id_patient/',function(req,res){ 
var query = "select * from Patient where id_patient = " + req.params.id_patient ; 
connection.query(query,function(error,results){
if (error) throw error;
res.send(results);
})
});

好吧,当我使用路径在浏览器上进行测试时:

http://localhost:8082/getPatient2/1

它正常显示结果,但这不是我在身份验证中需要的,它应该是电话号码和密码,这意味着:

app.get('/xxxxx',function(req,res){ 
var query = "select * from Patient where phone_patient =" + req.params.tel + "and paasword=" + 
req.params.pass; 
connection.query(query,function(error,results){
if (error) throw error;
res.send(results);
})
});

我尝试了很多路径,但总是出现错误,我搜索了很多文档,但没有找到任何带有“和”查询的示例

我真的希望你能帮助我提前谢谢你

路径应该提供这 2 个参数,例如,其中任何一个都应该有效:

/get-patient/:tel/:pass
/get-patient/tel/:tel/pass/:pass

此外,您的 SQL 查询中有一个错字: paasword

附带说明一下,请考虑至少使用 HTTPS 来通过网络传递密码,并使用数据库连接库的参数化查询功能。 此外,请确保您在数据库中散列密码。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM