GORM无法映射到结构体上


type StrategyAction1 struct {
	ID         int64  `json:"id"`         //编号
	Pushtype   string `json:"pushtype"`   //推送类型
}

type StrategyAction2 struct {
	ID         int64  `json:"id"`         //编号
	PushType   string `json:"pushtype"`   //推送类型
}

StrategyAction1与StrategyAction2的区别:仅仅是结构体内的 推送类型 属性命名不同

StrategyAction2使用了驼峰命名法,这是我以前写JAVA养成的习惯,在GORM中,应该采取StrategyAction1中Pushtype的命名方法,才能正确的映射到对应的属性上去。

指定gorm column名称就好了: PushType `gorm:"column:pushtype" json:"pushtype"`,gorm默认是将PushType映射为push_type

学生浅薄 望众师指点
原文地址:https://www.cnblogs.com/Nihility/p/14695649.html