From 88b9cd5a9db7d068001e2717383785127a13fccb Mon Sep 17 00:00:00 2001 From: "DESKTOP-4RNDQIC\\29019" <290198252@qq.com> Date: Thu, 4 Mar 2021 21:46:04 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E7=89=88=E6=9C=AC=E5=8F=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- controller/blog.go | 21 +++++++++++---------- model/blog.go | 4 ++-- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/controller/blog.go b/controller/blog.go index 36c9abe..7b4105b 100644 --- a/controller/blog.go +++ b/controller/blog.go @@ -173,6 +173,17 @@ func UpdateArtilce(c *gin.Context) { c.JSON(200, rsp) }() + + + er := c.BindJSON(&req) + if nil != er { + logs.Error(er.Error()) + return + } + if req.Title == "" { + rsp.Msg = "title required" + return + } query := fmt.Sprintf("select * from doc where doc.id = '%d'", req.ID) docs := []model.Doc{} e := db.GetMysqlClient().Query2(query, &docs) @@ -184,16 +195,6 @@ func UpdateArtilce(c *gin.Context) { rsp.Msg = "不存在该" return } - - er := c.BindJSON(&req) - if nil != er { - logs.Error(er.Error()) - return - } - if req.Title == "" { - rsp.Msg = "title required" - return - } e = model.UpdateDoc( model.Doc{ Type: int32(req.Type), diff --git a/model/blog.go b/model/blog.go index 69ca005..1f9f1b9 100644 --- a/model/blog.go +++ b/model/blog.go @@ -88,9 +88,9 @@ func CreateDoc(doc Doc) error { UpdateDoc 更新文档 */ func UpdateDoc(doc Doc) error { - sql := fmt.Sprintf(`update doc set doc.author = '%s' ,doc.title = '%s',doc.type = '%d',doc.content = '%s' ,doc.update_time = '%s' where doc.id = '%d'; `, + sql := fmt.Sprintf(`update doc set doc.author = '%s' ,doc.title = '%s',doc.type = '%d',doc.content = '%s' ,doc.update_time = '%s' ,doc.version = '%d' where doc.id = '%d'; `, doc.Author, doc.Title, doc.Type, - strings.Replace(doc.Content, "'", "\\'", -1), time.Now().Format("2006-01-02 15:04:05"), doc.ID) + strings.Replace(doc.Content, "'", "\\'", -1), time.Now().Format("2006-01-02 15:04:05"),doc.Version, doc.ID) _, e := db.GetMysqlClient().Query(sql) if nil != e { logs.Error(e.Error())