Beego model 增删改查

插入
o := orm.NewOrm()

user := UserInfo{Username: "zhangsan1", Password: "123456"}
id, err := o.Insert(&user)
c.Ctx.WriteString(fmt.Sprintf("操作数据库id=%d err:%v",id,err))
fmt.Println("\n")
user = UserInfo{Username: "lisi", Password: "654321"}
id, err= o.Insert(&user)
c.Ctx.WriteString(fmt.Sprintf("操作数据库id=%d err:%v",id,err))

 

修改
user := UserInfo{Username: "list", Password: "1234"}
user.Id = 13
o := orm.NewOrm()
o.Update(&user)
c.Ctx.WriteString(fmt.Sprintf("操作数据库user:%v", user))

 

读取
o := orm.NewOrm()
user := UserInfo{Id: 13}
o.Read(&user)
c.Ctx.WriteString(fmt.Sprintf("操作数据库user:%v", user))

 

删除
o := orm.NewOrm()
user := UserInfo{Id: 13}
o.Delete(&user)
c.Ctx.WriteString(fmt.Sprintf("操作数据库user:%v", user))

 

posted on 2020-10-15 20:10  星河赵  阅读(244)  评论(0编辑  收藏  举报

导航