react js与mysql,如何使用select与args?

react js与mysql,如何使用select与args?,mysql,node.js,reactjs,Mysql,Node.js,Reactjs,我正在使用mysql研究react js和nodejs。我看到了很多只使用no-args-select的例子。但是我想使用select和一些参数。我写了我的代码。但是在req.body中,没有设置参数。我该修什么 反应 节点 在React代码中,尝试将body作为对象传递body:JSON.stringify({“va”:va}) 然后在节点代码中,您可以访问va变量- const body = JSON.parse(req.body); const params = [body.va];

我正在使用mysql研究react js和nodejs。我看到了很多只使用no-args-select的例子。但是我想使用select和一些参数。我写了我的代码。但是在req.body中,没有设置参数。我该修什么

反应

节点


在React代码中,尝试将body作为对象传递
body:JSON.stringify({“va”:va})
然后在节点代码中,您可以访问va变量-

 const body = JSON.parse(req.body);
 const params = [body.va];
另外,为了传递请求数据,您需要将http谓词更改为POST而不是GET。

我遵循了,但出现了错误。“this.state.customer.map不是函数”
app.get('/api/customers',(req,res)=>{
    let sql = "select * from customer where id=?";
    params=[req.body.va]; //no recommand, so I got error.

    connection.query(
        sql,params,
        (err,rows,fields)=>{
            res.send(rows);
        }
    )
});
 const body = JSON.parse(req.body);
 const params = [body.va];