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"
      }
    ]

请大佬指点一二,谢谢

阅读 2.9k
2 个回答

orm:"column(id)";json:"id" 这样呢

使用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

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题