请稍等 ...
×

采纳答案成功!

向帮助你的同学说点啥吧!感谢那些助人为乐的人

新建blog请求一次, 数据库写入两条, 没找到原因?麻烦老师提供下debug的思路, 谢谢

正在回答 回答被采纳积分+3

2回答

双越 2019-06-17 09:03:40

我看 https://coding.imooc.com/learn/questiondetail/125840.html 这里,你自己回复说已经解决了。

0 回复 有任何疑惑可以回复我~
提问者 GivenCui 2019-06-17 00:40:58


// controller/blog.js
const newBlog = (blogData = {}) => {
    const {
        title,
        content,
        author,
    } = blogData
    const createtime = Date.now()
    const sql = `insert into blogs (title, content, createtime, author) values ('${title}', '${content}', '${createtime}', '${author}');`
    return exec(sql).then((result) => {
        // console.log('inserData: ', result)
        // {
        //   fieldCount: 0,
        //   affectedRows: 1,
        //   insertId: 18,
        //   serverStatus: 2,
        //   warningCount: 0,
        //   message: '',
        //   protocol41: true,
        //   changedRows: 0
        // }
        return {
            id: result.insertId
        }
    })
}
// router/blog.js

const {
    path,
    body,
    query
} = req
const {
    id,
} = query
// 新建博客
if (path === '/api/blog/new') {
    // TODO: author为假数据, 需要处理完登录模块后再处理
    body.author = 'givencui_mock'
    return newBlog(body).then((data) => {
        return new SuccessModel(data)
    }).catch(err => {
        return new ErrorModel(err)
    })
}


0 回复 有任何疑惑可以回复我~
问题已解决,确定采纳
还有疑问,暂不采纳
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号