admin管理员组文章数量:1635850
最近刚接触golang,里面基础没有怎么看,只能在项目中边学边看记啦,昨天遇到了结构体报错的问题,今天终于解决了。废话不多说了直接上代码。
type Config struct {
id int
key string
val string
typ int
}
func regionAll()([]Config,error) {
mods := make([]Config,0)
error := DB.Select(&mods,"select * from config ")
fmt.Println(error)
return mods,error
}
运行后请求数据库查询会报错误:
non-struct dest type struct with >1 columns (4) 问题处理
后来发现结构体(struct)里面的成员变量首字母是区分大小写的,若首字母大写则该成员为公有成员(对外可见),否则是私有成员(对外不可见)。因为我要对外可见,所以把结构体里面的成员变量改成
type Config struct {
Id int
Key string
Val string
Typ int
}
执行之后报 missing destination name value in *[]main.Config 异常,然后修改结构体
type Config struct {
Id int `db:"id"`
Key string `db:"key"`
Val string `db:"value"`
Typ int `db:"type"`
}
再执行都解决的帮忙点个赞。
本文标签: typegtstructdestdestination
版权声明:本文标题:gonon-struct dest type struct with >1 columns (4) or missing destination name value in *[]main问题处理 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://m.elefans.com/dongtai/1729216164a1190458.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论