reflect.Value.Set using unaddressable value

后端 未结 3 2190
余生分开走
余生分开走 2021-02-13 10:36
g.GET(\"/\", func(c echo.Context) error {
    var users []models.User
    err := db.Find(users).Error
    if err != nil {
        fmt.Println(err)
    }
    return c.JSO         


        
3条回答
  •  隐瞒了意图╮
    2021-02-13 10:43

    You have to call Find with a pointer to the slice.

    err := db.Find(&users).Error
    

    relevant Gorm documentation: http://jinzhu.me/gorm/crud.html#query

提交回复
热议问题