首页 > 编程语言 > 详细

springmvc中@PathVariable传Double精度丢失

时间:2017-07-25 12:09:38      阅读:373      评论:0      收藏:0      [点我收藏+]

页面请求

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 类型,数字更精确

 

springmvc中@PathVariable传Double精度丢失

原文:http://www.cnblogs.com/skyessay/p/7233307.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!