type User struct{
Id int `json:"id" xorm:"not null pk autoincr INT(11)"`
Name string `json:"name"`
Password string `json:"-"`
}
提交json数据:
[
{
"name":"aaa",
"password":"123456"
},{
"name":"bbb",
"password":"123456"
},
]
var Users []models.User
_ = Ctx.ReadJSON(&Users)
for _,user:=range Users{
fmt.Println(user.Password)//这里打印出来的password是空的
}
使用json:"-"
把Password
字段隐藏起来的话,user.Password
为“”。
有什么简便办法既可以隐藏password字段,也可以在插入数据时也能读到passwrod字段
试了
orm:"-"
这种方法,也不行,难道真的要手动过滤这个隐藏字段吗??