项目采用先后端分离的方式开发,后台接口开发好后经过postman也测试经过了,可是集成前端的时候发出,后台LONG类型的数据到了前台后数度丢失了:前端
后台数据:spring
前台:json
最后一位精度丢失。后端
主要缘由多是js内部的数据表示问题,具体缘由还不太了解。app
解决方法:前后端分离
将long类型的数据转为string类型。post
可经过自定义spring ObjectMapper来统一实现:测试
@EnableTransactionManagement @MapperScan("com.makeronly.*.repo") @SpringBootApplication public class Application{ /** * 防止json时出现错误FAIL_ON_EMPTY_BEANS * @return */ @Bean public ObjectMapper objectMapper() { SimpleModule simpleModule = new SimpleModule(); simpleModule.addSerializer(Long.class, ToStringSerializer.instance); simpleModule.addSerializer(Long.TYPE, ToStringSerializer.instance); ObjectMapper myObjectMapper = new ObjectMapper(); myObjectMapper.registerModule(simpleModule); myObjectMapper.disable(SerializationFeature.FAIL_ON_EMPTY_BEANS); return myObjectMapper; } public static void main(String[] args){ SpringApplication.run(Application.class, args); }
主要是标红的这几句话实现。spa