在 axios PUT 端点中找不到端点 URL

Endpoint URL not found in axios PUT endpoint

当按下一个按钮时,我的应用程序假设从数据库中的当前数量中减去 1,其中项目的名称是“CrossBag”

我在客户端上的 PUT 端点:

confirm = () => {
    axios.put(`http://localhost:5000/merch/CrossBag`, {
        Quantity: this.state.merchInfo[0].Quantity - 1,
        });
};

我的 table 商品的结构,其中 Name 是主键:

端点的服务器端:

app.put('/merch/:name', function (req, res) {
  const { name } = req.params;
  const { Quantity } = req.body;

  connection.getConnection(function (err, connection) {
     if(err) {
         console.log(err)
         return
     }

     connection.query(`UPDATE merch SET Quantity = ${Quantity} WHERE name = ${name}`, function (error, results, fields) {
       
      if (error)
      {
        throw error;
      }
    });
   });
});

当我按下按钮时,它显示:

PUT http://localhost:5000/merch/CrossBag 404 (Not Found)

我对如何专门更新该行的数量感到有点困惑。我读到您需要某种 ID 来指定要更改的行,所以我将该 ID 作为我的主键(名称)。

谁能给我指导?

您需要像下面这样定义路由:

// this will match route like /merch/CrossBag or /merch/Blanket
app.put('/merch/:name', function (req, res) {
  const {name = '' } = req.params; 
  connection.getConnection(function (err, connection) {
     if(err) {
         console.log(err)
         return
     }
   });
});