SpringMVC数据格式转换报错:rejected value [065966] error in object 'command' on field 'imgNumber'


错误信息如下:
org.springframework.validation.BindException:

首先这个问题可以确定为是数据格式转换异常。问题出在BeanPropertyBindingResult,imgNumber是数据库表中的一个字段,有一个对应的bean,SpringMVC就是通过这个
javaBean来实现数据格式转换的。我们输入的字符串 “65966” ,在向后台传递的过程中,需要转化成整数,SpringMVC会根据十六进制,把我们输入的十进制的数字进行

转换。

解决方法一:统一数据格式,如果可以统一数据格式的话,最好统一数据格式,这样就不会进行数据格式的转换,就可以有效避免这种数据格式转换的错误;
解决方法二,不使用javaBean的方式传递数据,而是直接通过request对象的getParameter("imgNumber") 方法来接收页面传递过来的参数。
具体如何操作,还是要结合具体的项目来。

WARN [http-8089-1] SimpleMappingExceptionResolver.logException(285) | Handler execution resulted in exception
org.springframework.web.bind.ServletRequestBindingException: Errors binding onto object 'command'; nested exception is org.springframework.validation.BindException: org.springframework.validation.BeanPropertyBindingResult: 1 errors
Field error in object 'command' on field 'imgNumber': rejected value [065966]; codes [typeMismatch.command.imgNumber,typeMismatch.imgNumber,typeMismatch.java.lang.Integer,typeMismatch]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [command.imgNumber,imgNumber]; arguments []; default message [imgNumber]]; default message [Failed to convert property value of type [java.lang.String] to required type [java.lang.Integer] for property 'imgNumber'; nested exception is java.lang.NumberFormatException: For input string: "65966"]
	at org.springframework.web.bind.ServletRequestDataBinder.closeNoCatch(ServletRequestDataBinder.java:119)
	at org.springframework.web.servlet.mvc.multiaction.MultiActionController.bind(MultiActionController.java:540)
	at org.springframework.web.servlet.mvc.multiaction.MultiActionController.invokeNamedMethod(MultiActionController.java:469)
	at org.springframework.web.servlet.mvc.multiaction.MultiActionController.handleRequestInternal(MultiActionController.java:409)
	at org.springframework.web.servlet.mvc.AbstractController.handleRequest(AbstractController.java:153)
	at org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter.handle(SimpleControllerHandlerAdapter.java:48)
	at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:874)
	at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:808)
	at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:476)
	at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:441)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)


Caused by: org.springframework.validation.BindException: org.springframework.validation.BeanPropertyBindingResult: 1 errors
Field error in object 'command' on field 'imgNumber': rejected value [065966]; codes [typeMismatch.command.imgNumber,typeMismatch.imgNumber,typeMismatch.java.lang.Integer,typeMismatch]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [command.imgNumber,imgNumber]; arguments []; default message [imgNumber]]; default message [Failed to convert property value of type [java.lang.String] to required type [java.lang.Integer] for property 'imgNumber'; nested exception is java.lang.NumberFormatException: For input string: "65966"]
	... 74 more
DEBUG [http-8089-1] HttpSessionContextIntegrationFilter.doFilterHttp(255) | SecurityContextHolder now cleared, as request processing completed
2016-5-18 20:05:59 org.apache.catalina.core.StandardWrapperValve invoke
严重: Servlet.service() for servlet dispatcher threw exception
org.springframework.validation.BindException: org.springframework.validation.BeanPropertyBindingResult: 1 errors
Field error in object 'command' on field 'imgNumber': rejected value [065966]; codes [typeMismatch.command.imgNumber,typeMismatch.imgNumber,typeMismatch.java.lang.Integer,typeMismatch]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [command.imgNumber,imgNumber]; arguments []; default message [imgNumber]]; default message [Failed to convert property value of type [java.lang.String] to required type [java.lang.Integer] for property 'imgNumber'; nested exception is java.lang.NumberFormatException: For input string: "65966"]
	at org.springframework.web.bind.ServletRequestDataBinder.closeNoCatch(ServletRequestDataBinder.java:119)
	at org.springframework.web.servlet.mvc.multiaction.MultiActionController.bind(MultiActionController.java:540)
	at org.springframework.web.servlet.mvc.multiaction.MultiActionController.invokeNamedMethod(MultiActionController.java:469)
	at org.springframework.web.servlet.mvc.multiaction.MultiActionController.handleRequestInternal(MultiActionController.java:409)
	at org.springframework.web.servlet.mvc.AbstractController.handleRequest(AbstractController.java:153)
	at org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter.handle(SimpleControllerHandlerAdapter.java:48)
	at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:874)
	at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:808)
	at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:476)
	at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:441)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
	at org.springframework.security.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:378)
	at org.springframework.security.intercept.web.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:109)
	at org.springframework.security.intercept.web.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:83)
	at org.springframework.security.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:390)
	at org.springframework.security.ui.SessionFixationProtectionFilter.doFilterHttp(SessionFixationProtectionFilter.java:67)
	at org.springframework.security.ui.SpringSecurityFilter.doFilter(SpringSecurityFilter.java:53)
	at org.springframework.security.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:390)
	at org.springframework.security.ui.ExceptionTranslationFilter.doFilterHttp(ExceptionTranslationFilter.java:101)
	at org.springframework.security.ui.SpringSecurityFilter.doFilter(SpringSecurityFilter.java:53)
	at org.springframework.security.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:390)
	at org.springframework.security.wrapper.SecurityContextHolderAwareRequestFilter.doFilterHttp(SecurityContextHolderAwareRequestFilter.java:91)
	at org.springframework.security.ui.SpringSecurityFilter.doFilter(SpringSecurityFilter.java:53)
	at org.springframework.security.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:390)
	at org.springframework.security.ui.AbstractProcessingFilter.doFilterHttp(AbstractProcessingFilter.java:278)
	at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
	at java.lang.Thread.run(Thread.java:662)

经过测试,当 imgNumber 输入下面的数值时,都会报错,当然,这些只是一部分,所有的情况不可能一一列举。
0659
06591
06592
06593
06594
06595
06596
06597
06598
06599
06590
0658
06581
06582
06583
06584
06585
06586
06587
06588
06589
06580
07659
01659
00657
00658
00659
006590
006590123
0596
0695
0569
0566
0865
0568
00568
5680

还有一点可以确定,就是,这个错误在进入后台controller方法之前就已经抛出了。


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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值