中山网站建设方案外包,前端开发软件哪个最好,建设网站需要哪些域名,网站建设 系统 排名#x1f61c;作 者#xff1a;是江迪呀✒️本文关键词#xff1a;日常BUG、BUG、问题分析☀️每日 一言 #xff1a;存在错误说明你在进步#xff01; 一、问题描述
数据库long类型Id:
前端返回的Id实体类:
Data
ApiModel(xxx)
public class … 作 者是江迪呀✒️本文关键词日常BUG、BUG、问题分析☀️每日 一言 存在错误说明你在进步 一、问题描述
数据库long类型Id:
前端返回的Id实体类:
Data
ApiModel(xxx)
public class TestVO{ApiModelProperty(id)private Long id;...
}前端拿到的Id:
{
id: 1535525132997402600,
attributeCode: COLOR,
attributeName: 颜色2,
attributeDesc: 颜色2,
createTime: 2022-06-11 15:31:35,
createUser: test
},二、问题原因
这是因为使用Long类型作id时前后端交互时数据在网络上传输会导致精度丢失。
三、问题解决
在返回给前端的Dto类中在Id上面加上下面的注解即可
JsonSerialize(using ToStringSerializer.class)这样id就正常了
{id: 1535525132997402625,attributeCode: COLOR,attributeName: 颜色2,attributeDesc: 颜色2,createTime: 2022-06-11 15:31:35,createUser: test
},}, 如果前端要传给后端id的话也会造成上面的问题。解决办法是前端将Long类型的字段转为String后端在将String 转为Long即可。