用node+ express写的中间件Api接口增删改查,sql语句在navicat测试能实现,在项目中就失效了
简单说就是
SQL:update article set title= '1' , about= 'qq1' , content= 'qwer' where title= '1'
navicat中连接mysql测试可行
在项目运行就只能在不改变title下更新about和content,只要更新title就其他两就无法更新
没有报错,项目是可以运行的,就是更新数据无变化
离谱,照理说sql语句能通过也没报错但又更新不了,不知道是那的问题,当局者迷,求指点下迷津!
问题相关代码,请勿粘贴截图
前端:
//vue前端获取数据
updatearticle(row) {
var title = row.title;
var about = row.about;
var content = row.content;
this.$http
.post(
"/api/article/update",
{
title: title,
about: about,
content: content,
},
{}
)
.then((response) => {
console.log(response);
});
//中间API接口
router.post('/update', (req, res) => {
var sql = $sql.article.update;
var params = req.body;
console.log(params);
conn.query(sql, [params.title, params.about, params.content, params.title], function (err, result) {
if (err) {
console.log("更新文章失败" + err);
}
if (result) {
jsonWrite(res, result);
console.log("更新文章成功");
}
})
});
//SQL语句
article: {
update: 'update article set title= ? , about= ? , content= ? where title= ? ',
},