码迷,mamicode.com
首页 > 编程语言 > 详细

springmvc中@PathVariable传Double精度丢失

时间:2017-07-25 12:41:31      阅读:135      评论:0      收藏:0      [点我收藏+]

标签:host   精度   code   get   请求   variable   print   数据   number   

页面请求

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精度丢失

标签:host   精度   code   get   请求   variable   print   数据   number   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!