gin + gorm 查询成功 数据表字段都存在 返回空数据

package model

import (
“github.com/jinzhu/gorm”
_ “github.com/jinzhu/gorm/dialects/mysql”
)

type Store struct {
*Model
Id int gorm:"primaryKey" json:"id"
Name string json:"name"
Enabled int json:"enabled"
Deleted int json:"deleted"
Email string json:"email"
Mobile string json:"mobile"
PerCapita string json:"per_capita"
Cif string json:"cif"
CreateTime string json:"create_time"
Guid string json:"guid"
MainBusiness string json:"main_business"
No string json:"no"
SupportedPaymentMethod string json:"supported_payment_method"
DeliveryDistance string json:"delivery_distance"
TakeawaySupportedPaymentMethod string json:"takeaway_supported_payment_method"
TakeawayMinimumConsumption int json:"takeaway_minimum_consumption"
Open int json:"open"
Disabled int json:"disabled"
Status int json:"status"
TakeawayStatus int json:"takeaway_status"
NotificationStatus int json:"notification_status"
IsAllowScan int json:"is_allow_scan"
About string json:"about"
ShowAboutMe int json:"show_about_me"
AboutCoverPath string json:"about_cover_path"
Seo *AutoGenerated json:"seo"
ReserveStatus int json:"reserve_status"
ShareImgs string json:"share_imgs"
ForbidCustomer string json:"forbid_customer"
WarningNum int json:"warning_num"
SendHome int json:"send_home"
PickUp int json:"pick_up"
OpenCustomerService int json:"open_customer_service"
TripartiteSalesmanId int json:"tripartite_salesman_id"
ThreePlatform string json:"three_platform"
Currency int json:"currency"
Outofstock int json:"outofstock"
}

type AutoGenerated struct {
Keyword string json:"keyword"
Description string json:"description"
}

func (store Store) TableName() string {
return “store”
}

func (store Store) GetAll(db gorm.DB) ([]Store, error) {
var rows []*Store
err := db.Find(&rows).Error
if err != nil {
return nil, err
}
return rows, nil
}

本作品采用《CC 协议》,转载必须注明作者和本文链接
讨论数量: 2

mysql 表字段以前的人以

file大驼峰命名查询不出来,以小写下划线命名可以查询出来这个需要做什么处理吗

1年前 评论

已解决select 把字段名重定义一下就可以了

1年前 评论

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!