首页 > 其他 > 详细

Gorm学习小记

时间:2020-03-27 10:10:02      阅读:57      评论:0      收藏:0      [点我收藏+]

Gorm学习手册:http://gorm.book.jasperxu.com/
Go学习中文网提供手册: https://books.studygolang.com/gorm/

1、模型结构体字段设置标签注意点:
* tag(如:gorm、json form)后面的冒号与双引号之间不能有空格;
* 同一种tag,不同属性定义使用“;”分隔;不同tag 使用空格“ ”分隔;
* 使用预加载Preload,需要在结构体中指明外键(不指名则默认是预加载表的主键作为外键)

type CheckResult struct {
	Id          uint   `gorm:"primary_key;auto_increment" json:"id"`
	WebId       uint   `gorm:"not null;"`
	ServerId    uint   `gorm:"not null;"`
	CheckInfo   []byte `gorm:"not null;"`
	CheckStatus uint   `gorm:"not null;default:1;"`
	CreateTime  uint   `gorm:"not null;"`
	UpdateTime  uint   `gorm:"not null;"`
	Web         Web
	Server      Server
}

Gorm学习小记

原文:https://www.cnblogs.com/xinxinmifan/p/golang_gorm_learning_notes.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!