Field error in object 'admin' on field 'id': rejected value [null]; codes [typeMismatch.admin.id,typeMismatch.id,typeMismatch.java.lang.Integer,typeMismatch]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [admin.id,id]; arguments []; default message [id]]; default message [Failed to convert property value of type 'java.lang.String' to required type 'java.lang.Integer' for property 'id'; nested exception is java.lang.NumberFormatException: For input string: "null"] at org.springframework.web.method.annotation.ModelAttributeMethodProcessor.resolveArgument(ModelAttributeMethodProcessor.java:157) ~[spring-web-5.0.2.RELEASE.jar:5.0.2.RELEASE] at org.springframework.web.method.support.HandlerMethodArgumentResolverComposite.resolveArgument(HandlerMethodArgumentResolverComposite.java:124) ~[spring-web-5.0.2.RELEASE.jar:5.0.2.RELEASE] at org.springframework.web.method.support.InvocableHandlerMethod.getMethodArgumentValues(InvocableHandlerMethod.java:161) [spring-web-5.0.2.RELEASE.jar:5.0.2.RELEASE] at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:131) [spring-web-5.0.2.RELEASE.jar:5.0.2.RELEASE] at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:102) [spring-webmvc-5.0.2.RELEASE.jar:5.0.2.RELEASE] at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:871) [spring-webmvc-5.0.2.RELEASE.jar:5.0.2.RELEASE] at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:777) [spring-webmvc-5.0.2.RELEASE.jar:5.0.2.RELEASE] at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87) [spring-webmvc-5.0.2.RELEASE.jar:5.0.2.RELEASE] at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:991) [spring-webmvc-5.0.2.RELEASE.jar:5.0.2.RELEASE] at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:925) [spring-webmvc-5.0.2.RELEASE.jar:5.0.2.RELEASE] at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:978) [spring-webmvc-5.0.2.RELEASE.jar:5.0.2.RELEASE] at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:881) [spring-webmvc-5.0.2.RELEASE.jar:5.0.2.RELEASE] at javax.servlet.http.HttpServlet.service(HttpServlet.java:652) [servlet-api.jar:4.0.FR] at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:855) [spring-webmvc-5.0.2.RELEASE.jar:5.0.2.RELEASE]
时间: 2023-09-23 07:03:51 浏览: 388
这个错误提示表明在处理请求时,Spring MVC无法将请求参数绑定到Admin类中的id属性。具体的错误原因是请求参数中的id属性的值为null,而Admin类中的id属性是一个Integer类型,无法将null转换成Integer类型,因此抛出了类型转换异常。
要解决这个问题,你可以检查一下请求参数中是否包含了id属性,以及id属性的值是否为null或者不符合Integer类型的格式。如果请求参数中没有包含id属性,可以添加该属性;如果id属性的值为null,可以设置一个默认值或者在Admin类中将id属性的类型改成int类型,避免出现类型转换异常。
相关问题
Resolved [org.springframework.web.method.annotation.ModelAttributeMethodProcessor$1: org.springframework.validation.BeanPropertyBindingResult: 4 errors<EOL>Field error in object 'order' on field 'order_id': rejected value [null]; codes [typeMismatch.order.order_id,typeMismatch.order_id,typeMismatch.int,typeMismatch]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [order.order_id,order_id]; arguments []; default message [order_id]]; default message [Failed to convert value of type 'null' to required type 'int'; nested exception is org.springframework.core.convert.ConversionFailedException: Failed to convert from type [null] to type [int] for value [null]; nested exception is java.lang.IllegalArgumentException: A null value cannot be assigned to a primitive type]<EOL>Field error in object 'order' on field 'phone': rejected value [null]; codes [typeMismatch.order.phone,typeMismatch.phone,typeMismatch.int,typeMismatch]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [order.phone,phone]; arguments []; default message [phone]]; default message [Failed to convert value of type 'null' to required type 'int'; nested exception is org.springframework.core.convert.ConversionFailedException: Failed to convert from type [null] to type [int] for value [null]; nested exception is java.lang.IllegalArgumentException: A null value cannot be assigned to a primitive type]<EOL>Field error in object 'order' on field 'buy': rejected value [null]; codes [typeMismatch.order.buy,typeMismatch.buy,typeMismatch.int,typeMismatch]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [order.buy,buy]; arguments []; default message [buy]]; default message [Failed to convert value of type 'null' to required type 'int'; nested exception is org.springframework.core.convert.ConversionFailedException: Failed to convert from type [null] to type [int] for value [null]; nested exception is java.lang.IllegalArgumentException: A null value cannot be assigned to a primitive type]<EOL>Field error in object 'order' on field 'total': rejected value [null]; codes [typeMismatch.order.total,typeMismatch.total,typeMismatch.int,typeMismatch]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [order.total,total]; arguments []; default message [total]]; default message [Failed to convert value of type 'null' to required type 'int'; nested exception is org.springframework.core.convert.ConversionFailedException: Failed to convert from type [null] to type [int] for value [null]; nested excep
这段错误信息表明在订单管理系统中,有一个名为order的对象中的四个字段(order_id, phone, buy, total)未能成功转换为int类型,因为它们的值为null,而null值无法赋给原始类型(int)。因此,在处理这些字段之前,需要先确保它们都赋有适当的值。您可以通过在代码中添加一些空值检查或默认值来解决这个问题。另外,您还可以考虑使用Java类中的包装类型(Integer)来代替原始类型(int),因为它们可以接受null值并且在使用时会更加灵活。
Resolved [org.springframework.validation.BindException: org.springframework.validation.BeanPropertyBindingResult: 2 errors Field error in object 'results' on field 'farmer_id': rejected value []; codes [typeMismatch.results.farmer_id,typeMismatch.farmer_id,typeMismatch.int,typeMismatch]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [results.farmer_id,farmer_id]; arguments []; default message [farmer_id]]; default message [Failed to convert property value of type 'java.lang.String' to required type 'int' for property 'farmer_id'; nested exception is java.lang.NumberFormatException: For input string: ""] Field error in object 'results' on field 'zone_id': rejected value []; codes [typeMismatch.results.zone_id,typeMismatch.zone_id,typeMismatch.int,typeMismatch]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [results.zone_id,zone_id]; arguments []; default message [zone_id]]; default message [Failed to convert property value of type 'java.lang.String' to required type 'int' for property 'zone_id'; nested exception is java.lang.NumberFormatException: For input string: ""]] 2023-06-10 11:49:06.814 WARN 20380 --- [nio-8080-exec-2] .w.s.m.s.DefaultHandlerExceptionResolver : Resolved [org.springframework.validation.BindException: org.springframework.validation.BeanPropertyBindingResult: 2 errors
这是一个 Spring MVC 框架的数据绑定异常,和之前的异常信息一样。这个异常信息说明在绑定客户端传递的数据到 Java 对象时,发生了数据类型不匹配或数据格式错误的情况,导致数据绑定失败。具体来说,这个异常信息指出了在绑定 'farmer_id' 和 'zone_id' 两个字段时,客户端传递的值无法转换为 int 类型,从而导致了数据绑定失败。
解决这个异常的方法和之前一样,可以检查客户端传递的数据是否符合要求,或者在 Java 对象中将对应的字段改为 String 类型。另外,也可以在 Spring MVC 的配置文件中配置自定义的数据绑定规则和异常处理方式来处理这种情况。
阅读全文