将结构体对应字段类型设为指针类型,一劳永逸,不用担心json序列化与反序列化问题
// User 用户结构体(对应mysql表)
type User struct {
Id int `db:"id"`
Code *string `db:"code"`
NickName string `db:"nick_name"`
Phone string `db:"phone"`
Password string `db:"password"`
CreateTime time.Time `db:"create_time"`
Sex int `db:"sex"`
Email string `db:"email"`
}
例如上述的Code字段,不设置为指针类型的话,查询时mysql里为null的话序列化就会出现“sqlx converting NULL to string is unsupported”