首页 > 编程语言 > 详细

goorm之结构体数组查询多个

时间:2020-05-25 00:10:09      阅读:145      评论:0      收藏:0      [点我收藏+]

首先需要创建一个结构体和数据库绑定

假设结构体长这样

type Topic struct {
ID uint
TheTopic string
Hash string
TopicType int
Answer string
Correct string
CreateTime int64
CreateIp string
AllHash string `gorm:"PRIMARY_KEY"`
CourseName string
}

则在数据库中是这样,表名topics

技术分享图片

其中有一点特别要注意 :单词开头要大写!单词开头要大写!单词开头要大写!

通过 AutoMigrate() 这个方法自动创建表

接着是查询:

var topics []Topic

看到中括号了吗,定义结构体数组

查询时记得传地址

db.Where(`id > ?`,xxx).Find(&topics)

大功告成

goorm之结构体数组查询多个

原文:https://www.cnblogs.com/lyj0309/p/12953635.html

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