gorm更新字段值+1或-1

func (xy *XJGYTopic) AdUpdateSignUpNum(id int64) bool {
    if xy.ID <= 0 {
        return false
    }
    if err := Db.Model(xy).Where("id = ? ", id).Update("sign_up_num", gorm.Expr("sign_up_num+ ?", 1)).Error; err != nil {
        return false
    }
    return true
}

 

posted @ 2022-08-10 16:13  hubb  阅读(1818)  评论(0编辑  收藏  举报