按下按鈕時,我的應用程式假設從資料庫中的當前數量中減去 1,其中專案的名稱為“CrossBag”
我在客戶端上的 PUT 端點:
confirm = () => {
axios.put(`http://localhost:5000/merch/CrossBag`, {
Quantity: this.state.merchInfo[0].Quantity - 1,
});
};
我的表商品的結構,其中 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 設為我的主鍵(名稱)。
誰能給我任何指導?
uj5u.com熱心網友回復:
您需要定義如下路線:
// 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
}
});
});
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/411773.html
標籤:
下一篇:在DataGrip(JetBrains)和MySQLWorkbench上查看相同的資料庫(將MySQLWB中使用的資料庫匯入到DAtaGrip)
