我是这个node.js的新手。我在node.js中使用mysql。我正在从url构建sql查询。有一个参数,它可以正常工作。
网址:
http://ipaddress:3002/users/Kappalur
通过使用以下代码,我提取Kappalur及其工作精细:
app.get('/users/:level', function (req, res) {
connection.query("select * from levels where level4= '"+req.params.level+"'", function(err, rows, fields) {
res.writeHead(200, { 'Content-Type': 'application/json'});
res.end(JSON.stringify(rows,null,"n"));
Now my requirement is i want to make "level4" to be dynamic..
现在考虑url为:
http://ipaddress:3002/users/level4/Kappalur
现在我如何更改上面的代码以从url中获取2个参数。帮我解决这个问题。。提前谢谢。
据我所知,您正在使用node.js.的express
框架
要检索多个URL参数,请使用与您在文章代码片段中使用的模式相同的模式:
app.get('/users/:level/:name', function (req, res) {
var level = req.params.level;
var name = req.params.name;