zoukankan      html  css  js  c++  java
  • Long类型传值前端精度丢失

    装载:https://blog.csdn.net/ht_kasi/article/details/81230234

    1.直接改成字符串

    2.加注解

    //向前端返回时将Long转成字符串
    public class LongJsonSerializer extends JsonSerializer<Long> {
        @Override
        public void serialize(Long value, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException, JsonProcessingException {
            String text = (value == null ? null : String.valueOf(value));
            if (text != null) {
                jsonGenerator.writeString(text);
            }
        }
    
    ————————————————
    版权声明:本文为CSDN博主「ht_kasi」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
    原文链接:https://blog.csdn.net/ht_kasi/article/details/81230234
    //将接收的前端字符串类型转换成Long类型
    public class LongJsonDeserializer extends JsonDeserializer<Long> {
        private static final Logger logger = LoggerFactory.getLogger(LongJsonDeserializer.class);
     
        @Override
        public Long deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException {
            String value = jsonParser.getText();
            try {
                return value == null ? null : Long.parseLong(value);
            } catch (NumberFormatException e) {
                logger.error("数据转换异常", e);
                return null;
            }
        }
    }
    ————————————————
    版权声明:本文为CSDN博主「ht_kasi」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
    原文链接:https://blog.csdn.net/ht_kasi/article/details/81230234

    字段上加注解

    @JsonDeserialize(using = LongJsonDeserializer.class)
        @JsonSerialize(using = LongJsonSerializer.class)
        private Long id;
  • 相关阅读:
    Gated Recurrent Unit (GRU)
    Long Short-Term Memory (LSTM)
    GBDT && XGBOOST
    记录一次网站打开卡--排故障过程
    linux下mysql5.5 5.6 5.7安装教程
    tomcat无法正常shutdown
    linux服务器被入侵的解决方法
    线上CPU 占用300%多-故障解决
    6流程控制-while
    7 流程控制-for序列 for字典
  • 原文地址:https://www.cnblogs.com/longsanshi/p/12662034.html
Copyright © 2011-2022 走看看