我有一个非常简单的客户数据输入应用程序。只有新的客户输入页面正在工作并且数据被插入到数据库中,但是当我在 mobileNo 字段中故意输入超过 10 位数字时,我在浏览器中出现错误。这是github链接https://github.com/kalyan4github/cdb.git
**the full error logs is type Exception report**
message Failed to convert value of type 'com.trickytechnos.cdb.domain.Customer' to required type 'java.lang.String'; nested exception is java.lang.IllegalStateException: Cannot convert value of type [com.trickytechnos.cdb.domain.Customer] to required type [java.lang.String]: no matching editors or conversion strategy found
description The server encountered an internal error that prevented it from fulfilling this request.
exception
org.springframework.beans.ConversionNotSupportedException: Failed to convert value of type 'com.trickytechnos.cdb.domain.Customer' to required type 'java.lang.String'; nested exception is java.lang.IllegalStateException: Cannot convert value of type [com.trickytechnos.cdb.domain.Customer] to required type [java.lang.String]: no matching editors or conversion strategy found
org.springframework.beans.TypeConverterSupport.doConvert(TypeConverterSupport.java:74)
org.springframework.beans.TypeConverterSupport.convertIfNecessary(TypeConverterSupport.java:40)
org.springframework.validation.DataBinder.convertIfNecessary(DataBinder.java:575)
org.springframework.web.servlet.mvc.support.RedirectAttributesModelMap.formatValue(RedirectAttributesModelMap.java:79)
org.springframework.web.servlet.mvc.support.RedirectAttributesModelMap.addAttribute(RedirectAttributesModelMap.java:71)
org.springframework.web.servlet.mvc.support.RedirectAttributesModelMap.addAttribute(RedirectAttributesModelMap.java:34)
com.trickytechnos.cdb.controller.CustomerController.addCustomer(CustomerController.java:54)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
java.lang.reflect.Method.invoke(Method.java:497)
org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:214)
org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:132)
org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:104)
org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:748)
org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:689)
org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:83)
org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:945)
org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:876)
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:931)
org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:833)
javax.servlet.http.HttpServlet.service(HttpServlet.java:646)
org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:807)
javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
com.github.dandelion.datatables.core.web.filter.DatatablesFilter.doFilter(DatatablesFilter.java:73)
root cause
java.lang.IllegalStateException: Cannot convert value of type [com.trickytechnos.cdb.domain.Customer] to required type [java.lang.String]: no matching editors or conversion strategy found
org.springframework.beans.TypeConverterDelegate.convertIfNecessary(TypeConverterDelegate.java:267)
org.springframework.beans.TypeConverterDelegate.convertIfNecessary(TypeConverterDelegate.java:93)
org.springframework.beans.TypeConverterSupport.doConvert(TypeConverterSupport.java:64)
org.springframework.beans.TypeConverterSupport.convertIfNecessary(TypeConverterSupport.java:40)
org.springframework.validation.DataBinder.convertIfNecessary(DataBinder.java:575)
org.springframework.web.servlet.mvc.support.RedirectAttributesModelMap.formatValue(RedirectAttributesModelMap.java:79)
org.springframework.web.servlet.mvc.support.RedirectAttributesModelMap.addAttribute(RedirectAttributesModelMap.java:71)
org.springframework.web.servlet.mvc.support.RedirectAttributesModelMap.addAttribute(RedirectAttributesModelMap.java:34)
com.trickytechnos.cdb.controller.CustomerController.addCustomer(CustomerController.java:54)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
java.lang.reflect.Method.invoke(Method.java:497)
org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:214)
org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:132)
org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:104)
org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:748)
org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:689)
org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:83)
org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:945)
org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:876)
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:931)
org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:833)
javax.servlet.http.HttpServlet.service(HttpServlet.java:646)
org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:807)
javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
com.github.dandelion.datatables.core.web.filter.DatatablesFilter.doFilter(DatatablesFilter.java:73)
note The full stack trace of the root cause is available in the Apache Tomcat/7.0.56 logs.
Apache Tomcat/7.0.56
这是控制台中的输出
Field error in object 'customer' on field 'mobileNo': rejected value [12345678912]; codes [Size.customer.mobileNo,Size.mobileNo,Size.java.lang.String,Size]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [customer.mobileNo,mobileNo]; arguments []; default message [mobileNo],10,0]; default message [mobileno must be 10 digit]
请帮助我了解为什么会出现此错误,并且验证消息显示在控制台中而不是 thymeleaf 模板中。