问题描述
当使用API 更新数据表中的记录时,会存在只需要更新部分字段的需求。
这里我使用了Gin 构建API, 通过Gorm进行数据表的操作
假设我们有如下的API 以及对应model的struct:
//API
PUT /users
//Body
{
"id": 16,
"realName": "Tester1"
}
type SysUser struct {
ID int64 `gorm:"column:id;primaryKey;autoIncrement:true" json:"id"` // id
Username string `gorm:"column:username;not null" json:"username"` // 用户名
Password string `gorm:"column:password" json:"password"` // 密码 RealName string `gorm:"column:real_name" json:"real_name"` // 真名
Email strin