#NodeJS项目#Mysql语句出错

router.get('/api/goods/findone', function(req, res, next) {
let id = req.query.id;
connection.query("select * from goods where id="+id+"", function (error, results, fields) {
if (error) throw error;
res.send({
code:"0",
data:results
})
});
});


//报错
C:\Users\pdm\Desktop\FoodieApp\server>npm start

server@0.0.0 start
node ./bin/www
C:\Users\pdm\Desktop\FoodieApp\server\node_modules_mysql@2.18.1@mysql\lib\protocol\Parser.js:437
throw err; // Rethrow non-MySQL errors
^
Error: ER_BAD_FIELD_ERROR: Unknown column 'undefined' in 'where clause'
code: 'ER_BAD_FIELD_ERROR',
errno: 1054,
sqlMessage: "Unknown column 'undefined' in 'where clause'",
sqlState: '42S22',
index: 0,
sql: 'select * from goods where id=undefined'


//请求详情id
getData(id){
$http.request({
url:'/goods/findone',
data:{
id
}
}).then((res)=> {
console.log("res: " + JSON.stringify(res));
}).catch(()=> {
uni.showToast({
title: '请求失败',
icon:"none"
});
})

拼接的id返回有问题,是一个undefined类型
sql: 'select * from goods where id=undefined'

img