后端id
前端id
问题分析:
前端接收数字参数类型为 number
number的长度精确为16位
而雪花算法的长度为19位
解决方法1:
将数据库中的转换为String类型 (不建议 因为Long类型性能更好)
方案2:
在Spring Boot应用中,使用Jackson进行JSON序列化的时候将Long类型ID转成String响应给前端。
@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;
}
}
雪花算法精度问题完美解决了