jinzhu / copier

Copier for golang, copy value from struct to struct and more
MIT License
5.57k stars 489 forks source link

gorm查询出来的结构体COPY 的时候ID,CreatedAt,UpdatedAt没有成功, #221

Open hjw33210 opened 4 weeks ago

hjw33210 commented 4 weeks ago

value := &sysV1.Users{} err := copier.Copy(value, record) if err != nil { return nil, err }

value.Dept.Id = record.Dept.ID
for i, role := range value.Roles {
    role.Id = record.Roles[i].ID
    role.CreatedAt = record.Roles[i].CreatedAt.Format(time.RFC3339)
    role.UpdatedAt = record.Roles[i].UpdatedAt.Format(time.RFC3339)
}
value.Id = record.ID
value.Dept.CreatedAt = record.Dept.CreatedAt.Format(time.RFC3339)
value.Dept.UpdatedAt = record.Dept.UpdatedAt.Format(time.RFC3339)
value.CreatedAt = record.CreatedAt.Format(time.RFC3339)
value.UpdatedAt = record.UpdatedAt.Format(time.RFC3339)

需要自行再次添加