博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Spring MVC 学习笔记 data binding
阅读量:5088 次
发布时间:2019-06-13

本文共 7087 字,大约阅读时间需要 23 分钟。

   最近在实验Spring的时候遇到了一个问题:

SEVERE: Servlet.service() for servlet [DispatcherServlet] in context with path [/ExtProjectDemo] threw exception [Request processing failed; nested exception is org.springframework.validation.BindException: org.springframework.validation.BeanPropertyBindingResult: 2 errorsField error in object 'sysPersonModel' on field 'csrq': rejected value [1965-06-25]; codes [typeMismatch.sysPersonModel.csrq,typeMismatch.csrq,typeMismatch.java.util.Date,typeMismatch]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [sysPersonModel.csrq,csrq]; arguments []; default message [csrq]]; default message [Failed to convert property value of type 'java.lang.String' to required type 'java.util.Date' for property 'csrq'; nested exception is org.springframework.core.convert.ConversionFailedException: Failed to convert from type java.lang.String to type java.util.Date for value '1965-06-25'; nested exception is java.lang.IllegalArgumentException]Field error in object 'sysPersonModel' on field 'ryid': rejected value []; codes [typeMismatch.sysPersonModel.ryid,typeMismatch.ryid,typeMismatch.int,typeMismatch]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [sysPersonModel.ryid,ryid]; arguments []; default message [ryid]]; default message [Failed to convert property value of type 'java.lang.String' to required type 'int' for property 'ryid'; nested exception is java.lang.NumberFormatException: For input string: ""]] with root causeorg.springframework.validation.BindException: org.springframework.validation.BeanPropertyBindingResult: 2 errorsField error in object 'sysPersonModel' on field 'csrq': rejected value [1965-06-25]; codes [typeMismatch.sysPersonModel.csrq,typeMismatch.csrq,typeMismatch.java.util.Date,typeMismatch]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [sysPersonModel.csrq,csrq]; arguments []; default message [csrq]]; default message [Failed to convert property value of type 'java.lang.String' to required type 'java.util.Date' for property 'csrq'; nested exception is org.springframework.core.convert.ConversionFailedException: Failed to convert from type java.lang.String to type java.util.Date for value '1965-06-25'; nested exception is java.lang.IllegalArgumentException]Field error in object 'sysPersonModel' on field 'ryid': rejected value []; codes [typeMismatch.sysPersonModel.ryid,typeMismatch.ryid,typeMismatch.int,typeMismatch]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [sysPersonModel.ryid,ryid]; arguments []; default message [ryid]]; default message [Failed to convert property value of type 'java.lang.String' to required type 'int' for property 'ryid'; nested exception is java.lang.NumberFormatException: For input string: ""]    at org.springframework.web.method.annotation.ModelAttributeMethodProcessor.resolveArgument(ModelAttributeMethodProcessor.java:111)    at org.springframework.web.method.support.HandlerMethodArgumentResolverComposite.resolveArgument(HandlerMethodArgumentResolverComposite.java:75)    at org.springframework.web.method.support.InvocableHandlerMethod.getMethodArgumentValues(InvocableHandlerMethod.java:156)    at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:117)    at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:96)    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:617)    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:578)    at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:80)    at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:923)    at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:852)    at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:882)    at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:789)    at javax.servlet.http.HttpServlet.service(HttpServlet.java:646)    at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)    at cn.telchina.platform.filter.SafeFilter.doFilter(SafeFilter.java:103)    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)    at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501)    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1040)    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:607)    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:316)    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)    at java.lang.Thread.run(Thread.java:722)

 

使用的版本是:Spring3.1.2

 

如何解决呢?

解决参考文章:

 

PS:

  有另外一种解决方案,所有的入参只接受一个String串,也就是将参数打包传递,传递到后台之后,自己解析,这样每个方法都只需要一个参数。

  然后每个方法内部根据业务要求转换成bean,或者Map。

  

  实际上也挺好,尤其在各种复杂参数的情况下。

转载于:https://www.cnblogs.com/sdjnzqr/p/4300921.html

你可能感兴趣的文章
计算机的核心 --CPU
查看>>
linux下安装tomcat8
查看>>
JZOJ5906【NOIP2018模拟10.15】传送门
查看>>
字符串和十六进制数的相互转换
查看>>
闭包函数与装饰器
查看>>
UIImage图片处理
查看>>
Android触控屏幕Gesture(GestureDetector和SimpleOnGestureListener的使用教程)
查看>>
通过 ANE(Adobe Native Extension) 启动Andriod服务 推送消息(四)
查看>>
ListableBeanFactory
查看>>
Storm:最火的流式处理框架
查看>>
MyBatis中关于resultType和resultMap的区别
查看>>
ROS学习(二)运行keyboard
查看>>
读取并解析properties文件
查看>>
H3C命令5
查看>>
生日蛋糕
查看>>
电梯的一点浅优化
查看>>
我要去做it培训讲师了
查看>>
IIS 网站无法访问
查看>>
Steamroller
查看>>
开通博客记录
查看>>