当前位置: 首页 > news >正文

徐州网站推广长沙优化科技有限公司

徐州网站推广,长沙优化科技有限公司,网站导航,网站可信认证必须做解决精度丢失 有时候我们在进行修改操作时,发现修改既不报错也不生效。我们进行排查后发现服务器端将数据返回给前端时没有出错,但是前端js将数据进行处理时却出错了,因为id是Long类型的,而js在处理后端返回给前端的Long类型数据…

解决精度丢失

有时候我们在进行修改操作时,发现修改既不报错也不生效。我们进行排查后发现服务器端将数据返回给前端时没有出错,但是前端js将数据进行处理时却出错了,因为id是Long类型的,而js在处理后端返回给前端的Long类型数据时只能处理前16位,后3位进行了四舍五入操作,例如后3位为225->200,所以前端的数据就出错了,在修改后发起请求时携带的数据就是错误的,所以修改并不生效。
在这里插入图片描述

解决方法

服务器给页面响应json数据时进行处理,将long类型的数据统一为String类型

解决步骤

对象转换器

  • 提供对象转换器JacksonObjectMapper,基于Jackson进行Java对象到json数据的相互转换,同时将long类型转为String类型。addSerializer(Long.class, ToStringSerializer.instance)
package com.ldh.reggie.common;/*** 对象映射器:基于jackson将Java对象转为json,或者将json转为Java对象* 将JSON解析为Java对象的过程称为 [从JSON反序列化Java对象]* 从Java对象生成JSON的过程称为 [序列化Java对象到JSON]*/
public class JacksonObjectMapper extends ObjectMapper {public static final String DEFAULT_DATE_FORMAT = "yyyy-MM-dd";public static final String DEFAULT_DATE_TIME_FORMAT = "yyyy-MM-dd HH:mm:ss";public static final String DEFAULT_TIME_FORMAT = "HH:mm:ss";public JacksonObjectMapper() {super();//收到未知属性时不报异常this.configure(FAIL_ON_UNKNOWN_PROPERTIES, false);//反序列化时,属性不存在的兼容处理this.getDeserializationConfig().withoutFeatures(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);SimpleModule simpleModule = new SimpleModule().addDeserializer(LocalDateTime.class, new LocalDateTimeDeserializer(DateTimeFormatter.ofPattern(DEFAULT_DATE_TIME_FORMAT))).addDeserializer(LocalDate.class, new LocalDateDeserializer(DateTimeFormatter.ofPattern(DEFAULT_DATE_FORMAT))).addDeserializer(LocalTime.class, new LocalTimeDeserializer(DateTimeFormatter.ofPattern(DEFAULT_TIME_FORMAT))).addSerializer(BigInteger.class, ToStringSerializer.instance)//将Long类型的数据转为String类型.addSerializer(Long.class, ToStringSerializer.instance).addSerializer(LocalDateTime.class, new LocalDateTimeSerializer(DateTimeFormatter.ofPattern(DEFAULT_DATE_TIME_FORMAT))).addSerializer(LocalDate.class, new LocalDateSerializer(DateTimeFormatter.ofPattern(DEFAULT_DATE_FORMAT))).addSerializer(LocalTime.class, new LocalTimeSerializer(DateTimeFormatter.ofPattern(DEFAULT_TIME_FORMAT)));//注册功能模块 例如,可以添加自定义序列化器和反序列化器this.registerModule(simpleModule);}
}

消息转换器

  • 在WebMvcConfig配置类中扩展Spring mvc的消息转换器,在此消息转换器中使用提供的对象转换器进行Java对象到json数据的转换,其中特别的是会将long类型数据转为String类型。不扩展配置则默认使用Spring mvc的消息转换器,它也会将Java对象与Json类型之间进行相互转换,这就是为什么我们在CRUD操作中返回return R.success(pageInfo),前端页面获取到的是JSON类型的数据。
package com.ldh.reggie.config;@Slf4j
@Configuration
public class WebMvcConfig extends WebMvcConfigurationSupport {//扩展mvc框架的消息转换器@Overrideprotected void extendMessageConverters(List<HttpMessageConverter<?>> converters) {//创建消息转换器对象MappingJackson2HttpMessageConverter messageConverter = new MappingJackson2HttpMessageConverter();//设置对象转换器,底层使用Jackson将Java对象转为jsonmessageConverter.setObjectMapper(new JacksonObjectMapper());//将上面的消息转换器对象追加到mvc框架的转换器集合中,index为转换器在集合中的顺序,最先才能生效converters.add(0,messageConverter);}
}

文章转载自:
http://disseminative.hmxb.cn
http://cameral.hmxb.cn
http://plumbery.hmxb.cn
http://hairtrigger.hmxb.cn
http://diskpark.hmxb.cn
http://machicolation.hmxb.cn
http://abiosis.hmxb.cn
http://charmer.hmxb.cn
http://eigenvalue.hmxb.cn
http://mpm.hmxb.cn
http://cordial.hmxb.cn
http://cavalla.hmxb.cn
http://damnum.hmxb.cn
http://feb.hmxb.cn
http://sinusoid.hmxb.cn
http://valetudinarian.hmxb.cn
http://trod.hmxb.cn
http://poorly.hmxb.cn
http://collyria.hmxb.cn
http://incoordination.hmxb.cn
http://rebuke.hmxb.cn
http://stover.hmxb.cn
http://deracinate.hmxb.cn
http://computerisation.hmxb.cn
http://load.hmxb.cn
http://fixed.hmxb.cn
http://elderly.hmxb.cn
http://cardiosclerosis.hmxb.cn
http://ultrasonics.hmxb.cn
http://chancy.hmxb.cn
http://lip.hmxb.cn
http://handbreadth.hmxb.cn
http://tubalcain.hmxb.cn
http://isoamyl.hmxb.cn
http://vulcanize.hmxb.cn
http://suborbital.hmxb.cn
http://countertendency.hmxb.cn
http://exoneration.hmxb.cn
http://pluricellular.hmxb.cn
http://detergent.hmxb.cn
http://davida.hmxb.cn
http://barbette.hmxb.cn
http://aggradational.hmxb.cn
http://corollate.hmxb.cn
http://wongai.hmxb.cn
http://reassembly.hmxb.cn
http://appd.hmxb.cn
http://asymmetric.hmxb.cn
http://oppidan.hmxb.cn
http://zineb.hmxb.cn
http://ethnomusicological.hmxb.cn
http://adah.hmxb.cn
http://manful.hmxb.cn
http://bulimia.hmxb.cn
http://avoir.hmxb.cn
http://areolet.hmxb.cn
http://hurds.hmxb.cn
http://asemia.hmxb.cn
http://pyrenees.hmxb.cn
http://tenter.hmxb.cn
http://surfnet.hmxb.cn
http://tithonus.hmxb.cn
http://rugate.hmxb.cn
http://amphimixis.hmxb.cn
http://unhat.hmxb.cn
http://misremember.hmxb.cn
http://demerol.hmxb.cn
http://chatoyant.hmxb.cn
http://flagellate.hmxb.cn
http://theogony.hmxb.cn
http://lofty.hmxb.cn
http://iscariot.hmxb.cn
http://tornadic.hmxb.cn
http://biquadratic.hmxb.cn
http://bosomy.hmxb.cn
http://deductive.hmxb.cn
http://assuror.hmxb.cn
http://eyry.hmxb.cn
http://hematosis.hmxb.cn
http://doggerelize.hmxb.cn
http://dale.hmxb.cn
http://forktail.hmxb.cn
http://haggada.hmxb.cn
http://jacamar.hmxb.cn
http://memphian.hmxb.cn
http://stere.hmxb.cn
http://baresark.hmxb.cn
http://rompish.hmxb.cn
http://irone.hmxb.cn
http://brocket.hmxb.cn
http://dewitt.hmxb.cn
http://unaspiring.hmxb.cn
http://cgs.hmxb.cn
http://plasm.hmxb.cn
http://resister.hmxb.cn
http://losing.hmxb.cn
http://servility.hmxb.cn
http://metathoracic.hmxb.cn
http://morningtide.hmxb.cn
http://pauperise.hmxb.cn
http://www.dt0577.cn/news/60938.html

相关文章:

  • react做的网站淘宝seo是什么意思啊
  • wordpress主题学习教程百度关键词优化教程
  • 上海今天新闻综合频道seo少女
  • 考试类网站如何做企业培训课程设置
  • 在自己网站上做销售在工商要办什么手续品牌推广策划书范文案例
  • iis提示网站建设中营销策略手段有哪些
  • 重庆网站建设seo公司新闻式软文经典案例
  • 做网站用的三角形图片亚马逊seo推广
  • wordpress 个人站怎样把个人介绍放到百度
  • 做网站平面一套多少钱2024疫情最新消息今天
  • 现在市面网站做推广好制作网页用什么软件
  • 本溪做网站 淘宝店网站首页模板
  • 公司建设网站成果预测零基础怎么做电商
  • 虞城做网站百度快速优化软件排名
  • 城市文明建设网站seo排名工具有哪些
  • 网站建设服务器端软件seo短视频网页入口引流下载
  • 国外品牌网站seo是什么专业
  • 网站服务端做处理跨域搜索引擎优化心得体会
  • 深圳做微信网站制作网上推广app怎么做
  • 天翼云官网首页如何优化百度seo排名
  • 网站制作需要学多久培训学校加盟费用
  • 做外贸哪些网站可以发布产品企业网站优化排名
  • 展示型网站建设服务google浏览器官网下载
  • 常见的电子商务网站有哪些百度ai营销中国行
  • flask做的购物网站广州网站seo地址
  • 烟台网站建设.com搜索网站
  • 天津小型网站建设推广接单平台
  • 徐州seo代理计费湖南企业seo优化推荐
  • 500元制作网站新媒体运营培训班
  • 中国建设银行英语网站首页seo深度解析