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;
  • 相关阅读:
    Validator 字段验证
    DRF实现发送短信验证码接口
    云片网发送短信验证码
    DRF自定义用户认证
    php服务器端与android客户端通信问题
    转 java调用php的webService
    Ubuntu12.04安装vim7.3
    ubuntu12.10更新源
    源列表
    Ubuntu 12.10 用wubi安装到硬盘中
  • 原文地址:https://www.cnblogs.com/longsanshi/p/12662034.html
Copyright © 2011-2022 走看看