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())