处理这种问题有两种方案,要么后端出处理,要么前端处理
后端处理:
直接把id类型改为String就行,这样是可以,但是我们如果非要用Long呢?
我们可以给对应的实体类主键属性加入注解@JsonSerialize
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
@JsonSerialize(using = ToStringSerializer.class)
@TableId
private Long id;
前端处理:
前端一般都是用axios进行数据请求,我们通过引入json-bigint来解决
yarn add json-bigint
//或
npm install json-bigint
在封装的请求工具类中添加如下代码即可。
axios.defaults.transformResponse = [
function (data) {
const json = JSONBIG({
storeAsString: true
})
const res = json.parse(data)
return res
}
]
两种方案皆可。