beego curd Values 方法的疑问

我通过使用Values方法获得一定的map

var radio []orm.Params
num, _ := orm.NewOrm().
            QueryTable("product_album").
            Filter("product_id", id).
            Filter("state", 1).
            Values(&radio)

但获得的结果首字母都是大写,我已经在model内设置了小写的规则

type ProductAlbum struct {
    Id   int `json:"id"`
    ProductId int `json:"product_id"`
    Name string `json:"name"`
    Url  string `json:"url"`
    State string `json:"state"`
}

错误的结果

"radio": [
      {
        "Id": 37,
        "Name": "图片",
        "ProductId": 9,
        "State": "0",
        "Url": "7d9006e1d73d527662e598c1856327f28742"
      },
      {
        "Id": 55,
        "Name": "图片",
        "ProductId": 9,
        "State": "0",
        "Url": "38909849c3289db116c020c3d34cfb6f3975"
      },
      {
        "Id": 56,
        "Name": "图片",
        "ProductId": 9,
        "State": "0",
        "Url": "a164deb99004f9647f87f21771d19b468181"
      }
    ]

期望的结果

"radio": [
      {
        "id": 37,
        "name": "图片",
        "productId": 9,
        "state": "0",
        "url": "7d9006e1d73d527662e598c1856327f28742"
      },
      {
        "id": 55,
        "name": "图片",
        "productId": 9,
        "state": "0",
        "url": "38909849c3289db116c020c3d34cfb6f3975"
      },
      {
        "id": 56,
        "name": "图片",
        "productId": 9,
        "state": "0",
        "url": "a164deb99004f9647f87f21771d19b468181"
      }
    ]

请大佬指点一二,谢谢

阅读 936
评论
    2 个回答
    • 2
    • 新人请关照

    使用json转一下就可以了

    package main
    
    import (
        "fmt"
        "gopkg.in11/square/go-jose.v2/json"
    )
    
    type ProductAlbum struct {
        Id   int `orm:"column(id)" json:"id"`
        ProductId int `json:"product_id"`
        Name string `json:"name"`
    }
    
    func main() {
        p := ProductAlbum{Id:1,ProductId:2,Name:"知了课堂"}
    
        json_ret,err := json.MarshalIndent(p,""," ")
        fmt.Println(err)
        fmt.Println(string(json_ret))
    
    }

    image.png

      相似问题
      推荐文章