zoukankan      html  css  js  c++  java
  • springmvc中@PathVariable传Double精度丢失

    页面请求

    http://localhost:8080/test/3.201

    后端接受数据

    /**
         * 测试
         *
         * @param number
         */
        @RequestMapping(value = "/test/{number}", method = RequestMethod.GET)
        public void test(@PathVariable Double number) {
            System.out.println("数字:" + number);
        }

    结果

    数字:3.0

    改为下面的方式就可以

    /**
         * 测试
         *
         * @param number
         */
        @RequestMapping(value = "/test/{number:.+}", method = RequestMethod.GET)
        //或者@RequestMapping(value = "/test/{number:.*}", method = RequestMethod.GET)
        public void test(@PathVariable Double number) {
            System.out.println("数字:" + number);
        }

    建议传递带小数类型,最好用实体类接受,属性放在实体类中,用 BigDecimal 类型,数字更精确

  • 相关阅读:
    悲观锁乐观锁实战
    悲观锁
    乐观锁
    mysql数据库怎么设置乐观锁
    猴子吃桃问题
    算法题
    面试总结
    分布式系统理论(二):一致性协议Paxos
    职工工资管理
    79-WordSearch
  • 原文地址:https://www.cnblogs.com/skyessay/p/7233307.html
Copyright © 2011-2022 走看看