免费建站自助建站,即墨区城乡建设局网站官网,如何查询网站开发语言,东莞注册公司需要什么资料雪花算法ID#xff0c;对应的后端Long类型#xff0c;前端number类型#xff0c;它们的精度不一样#xff0c;导致精度丢失现象雪花算法得到的ID较长#xff0c;传到前端后#xff0c;精度丢失库中#xff1a;23754851322302474后端#xff1a;23754851322302474前端对应的后端Long类型前端number类型它们的精度不一样导致精度丢失现象雪花算法得到的ID较长传到前端后精度丢失库中23754851322302474后端23754851322302474前端23754851322302470解决方法将Long类型转成String再传给前端方法一单个注解JsonSerialize(using ToStringSerializer.class)private Long id;方法二统一配置package com.jiawa.wiki.config;import com.fasterxml.jackson.databind.ObjectMapper;import com.fasterxml.jackson.databind.module.SimpleModule;import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;import org.springframework.context.annotation.Bean;import org.springframework.context.annotation.Configuration;import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;/*** 统一注解解决前后端交互Long类型精度丢失的问题* 公众号甲蛙全栈* 关联视频课程《Spring Boot Vue3 前后端分离 实战wiki知识库系统》* https://coding.imooc.com/class/474.html*/Configurationpublic class JacksonConfig {Beanpublic ObjectMapper jacksonObjectMapper(Jackson2ObjectMapperBuilder builder) {ObjectMapper objectMapper builder.createXmlMapper(false).build();SimpleModule simpleModule new SimpleModule();simpleModule.addSerializer(Long.class, ToStringSerializer.instance);objectMapper.registerModule(simpleModule);return objectMapper;}}—————— THE END ——————原文链接http://www.jiawablog.com/detail?id156521212003094528甲蛙博客专注Java全栈技术分享