🍈作者:王甜甜(dabing)
# update 操作不成功
为什么上一条成功了,但是第二条不成功啊
经核查,是从前台获取到的 id 不正确,与 list 查询到的 id 不同,与数据库的 id 也不同,估计是雪花算法的 long 精度问题吧?
使用雪花算法作为 id 返回前端精度丢失问题解决
** 解决思路:** 后端的 ID (Long) ==> Jackson (Long 转 String) ==> 前端使用 String 类型的 ID, 前端使用 js string 精度就不会丢失了
参考:完美解决方案 - 雪花算法 ID 到前端之后精度丢失问题
配置文件:com.dabing.wiki.config.JacksonConfig.java
@Configuration | |
public class JacksonConfig { | |
@Bean | |
@Primary | |
@ConditionalOnMissingBean(ObjectMapper.class) | |
public ObjectMapper jacksonObjectMapper(Jackson2ObjectMapperBuilder builder) | |
{ | |
ObjectMapper objectMapper = builder.createXmlMapper(false).build(); | |
// 全局配置序列化返回 JSON 处理 | |
SimpleModule simpleModule = new SimpleModule(); | |
//JSON Long ==> String | |
simpleModule.addSerializer(Long.class, ToStringSerializer.instance); | |
objectMapper.registerModule(simpleModule); | |
return objectMapper; | |
} | |
} |