Bootstrap-Table中Long类型数据显示问题

Bootstrap-table中Long数据长度达到17位的时候,值显示到页面会有偏差(变大或变小)
,数据库关联的实体类中将某个字段设置为Long类型,查询出的数据比如该字段值为‘14762616457501159’,当显示到Bootstrap-Table中时变成了‘14762616457501160’,这是什么原因呢????

慕桂英4014372
浏览 604回答 1
1回答

ITMISS

我也遇上这个问题, 前端没有办法解决了 Long在前端大整数存在精度问题。 只能从后端把这个Long值转成String. 我用的spring boot, 代码如下, 解决了。@Configurationpublic class WebDataConvertConfig extends WebMvcConfigurerAdapter {&nbsp; &nbsp; public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {&nbsp; &nbsp; &nbsp; &nbsp; MappingJackson2HttpMessageConverter jackson2HttpMessageConverter = new MappingJackson2HttpMessageConverter();&nbsp; &nbsp; &nbsp; &nbsp; ObjectMapper objectMapper = new ObjectMapper();&nbsp; &nbsp; &nbsp; &nbsp; SimpleModule simpleModule = new SimpleModule();&nbsp; &nbsp; &nbsp; &nbsp; simpleModule.addSerializer(Long.class, ToStringSerializer.instance);&nbsp; &nbsp; &nbsp; &nbsp; simpleModule.addSerializer(Long.TYPE, ToStringSerializer.instance);&nbsp; &nbsp; &nbsp; &nbsp; objectMapper.registerModule(simpleModule);&nbsp; &nbsp; &nbsp; &nbsp; jackson2HttpMessageConverter.setObjectMapper(objectMapper);&nbsp; &nbsp; &nbsp; &nbsp; converters.add(jackson2HttpMessageConverter);&nbsp; &nbsp; }}
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript