https://github.com/jinzhu/gorm#define-models-scrests上找不到它
Michael的答案有效。但是,如果您想与Golang一起使用小数类型,则可以使用shopspring/Decimal
:
type TableName struct {
Amount decimal.Decimal `json:"amount" sql:"type:decimal(20,8);"`
}
text
.
。如果您使用的是Automigrate
,则可以在结构模型中给出GormSQL指令(在您的结构模型中)
如何构建表。尝试以下内容:
AutoMigrate()
type Product struct {
Id int
ProductName string `sql:"type:varchar(250);"`
Amount float32 `sql:"type:decimal(10,2);"`
}