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

posted @   ppjj  阅读(146)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?
历史上的今天:
2018-09-07 java中的不同的value类型从map中获取不同的value值
点击右上角即可分享
微信分享提示