1、表现
联调一个List接口,Postman自测得到的ID和前端调用得到的ID,结果不一样。前者结果:

后者结果:

同一份代码、同一个数据库,出现这种错误,大概率是类型转换时出问题了,但检查代码发现,后端并未涉及类型转换。
2、原因
前端浏览器会有数字溢出

3、解决
定义Vo类时,指定:将结构体对象序列化成json字符串时,将该字段的值转为字符串类型输出。

go
type Example struct {
ID uint64 `json:"id,string"`
}
// 示例
e := Example{ID: 123}
以上,序列化e对象,json串为:
go
{"id":"123"}
反之:序列化时,还是保持int型输出
go
type Example struct {
ID uint64 `json:"id"`
}
// 示例
e := Example{ID: 123}
// 序列化为 JSON: {"id":123}