报错 org.springframework.validation.BindException: org.springframework.validation.BeanPropertyBindingR

1.前台freemarker页面传参给后台时报错
报错信息:

2020-05-09 12:05:59.205  WARN 6624 --- [nio-8080-exec-2] .w.s.m.s.DefaultHandlerExceptionResolver : Resolved [org.springframework.validation.BindException: org.springframework.validation.BeanPropertyBindingResult: 2 errors
Field error in object 'product' on field 'originalPrice': rejected value [4,999]; codes [typeMismatch.product.originalPrice,typeMismatch.originalPrice,typeMismatch.java.lang.Integer,typeMismatch]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [product.originalPrice,originalPrice]; arguments []; default message [originalPrice]]; default message [Failed to convert property value of type 'java.lang.String' to required type 'java.lang.Integer' for property 'originalPrice'; nested exception is java.lang.NumberFormatException: For input string: "4,999"]
Field error in object 'product' on field 'promotePrice': rejected value [4,999]; codes [typeMismatch.product.promotePrice,typeMismatch.promotePrice,typeMismatch.java.lang.Integer,typeMismatch]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [product.promotePrice,promotePrice]; arguments []; default message [promotePrice]]; default message [Failed to convert property value of type 'java.lang.String' to required type 'java.lang.Integer' for property 'promotePrice'; nested exception is java.lang.NumberFormatException: For input string: "4,999"]]

前台代码

    <div class="layui-form-item layui-row layui-col-xs12">
        <label class="layui-form-label">原价</label>
        <div class="layui-input-block">
            <input type="text" class="layui-input"
                   lay-verify="required" name="originalPrice" id="originalPrice"  value="${(product.originalPrice)!}"  placeholder="请输入商品原价">
        </div>
    </div>

2.报错原因分析
通过报错信息可以看到是参数绑定异常 , 前台在给后台传商品价格的时候传的价格参数带千分符"4,999" , 应当传的参数是"4999" , 就导致参数绑定异常

前台传的参数:
在这里插入图片描述
3.解决方法
使用freemarker的数字内建函数 c函数 freemarker内建函数地址

value="${(product.originalPrice)!}"

改为

value="${((product.originalPrice)!)?c}"

将数值型数据去掉千分符,即可.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值