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
时间: 2024-04-02 22:33:30 浏览: 33
这是一个 Spring MVC 框架的数据绑定异常,和之前的异常信息一样。这个异常信息说明在绑定客户端传递的数据到 Java 对象时,发生了数据类型不匹配或数据格式错误的情况,导致数据绑定失败。具体来说,这个异常信息指出了在绑定 'farmer_id' 和 'zone_id' 两个字段时,客户端传递的值无法转换为 int 类型,从而导致了数据绑定失败。
解决这个异常的方法和之前一样,可以检查客户端传递的数据是否符合要求,或者在 Java 对象中将对应的字段改为 String 类型。另外,也可以在 Spring MVC 的配置文件中配置自定义的数据绑定规则和异常处理方式来处理这种情况。
相关问题
Resolved [org.springframework.http.converter.HttpMessageNotReadableException: JSON parse error
这个错误通常是由于在Spring框架中处理JSON请求时出现了问题导致的。具体来说,`HttpMessageNotReadableException` 表示无法读取HTTP消息的异常,而 `JSON parse error` 表示JSON解析错误。
可能的原因有:
1. 请求的JSON格式不正确:请确保您发送的JSON数据符合正确的格式要求,包括正确的数据结构和语法。
2. 缺少必需的依赖:请确保您的项目中包含了处理JSON的相关依赖库,例如 Jackson 或者 Gson。
3. 请求头设置不正确:请确保您在发送请求时设置了正确的Content-Type头信息,应该是`application/json`。
4. 控制器方法参数不匹配:请确保您的控制器方法能够正确地接收和解析JSON数据,可以使用 `@RequestBody` 注解来绑定请求体中的JSON数据到方法参数上。
5. 请求体为空:请确保您发送的请求体不为空,否则可能会导致解析错误。
请根据具体情况检查以上可能的原因,以便解决这个问题。如果您能提供更多的代码和错误信息,我可以更具体地帮助您解决这个问题。
错Resolved [org.springframework.http.converter.HttpMessageNotWritableException: No conve
错误 "Resolved [org.springframework.http.converter.HttpMessageNotWritableException: No converter found for return value of type: class com.cy.pj.common.vo.JsonResult]" 是由于返回值类型没有找到合适的转换器导致的。另外,错误信息中提到了"No converter for [class org.springframework.data.domain.PageImpl] with preset Content-Type 'null'",这是因为没有为PageImpl类型的对象找到合适的转换器。
要解决这个问题,可以尝试以下方法:
1. 确保你的控制器方法上使用了正确的produces属性,并指定了正确的媒体类型。
2. 检查你的代码是否正确配置了相应的转换器,确保转换器能够正确地将返回值转换为期望的响应类型。
3. 如果你使用的是自定义的返回类型,确保你已经正确配置了自定义的转换器。
4. 检查你的依赖库是否正确引入,并且版本匹配。
如果以上方法都没有解决问题,可以考虑查看Spring框架的官方文档或寻求相关社区的帮助来获取更详细的解决方案。
: org.springframework.http.converter.HttpMessageNotWritableException: No converter found for return value of type: class com.cy.pj.common.vo.JsonResult
: org.springframework.http.converter.HttpMessageNotWritableException: No converter for [class org.springframework.data.domain.PageImpl] with preset Content-Type 'null'
: @RequestMapping(value = "/administrator", produces = "application/json;charset=UTF-8")<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* [关于解决错误Resolved [org.springframework.http.converter.HttpMessageNotWritableException: No ...](https://blog.csdn.net/weixin_44957065/article/details/114979031)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"]
- *2* *3* [报错Resolved [org.springframework.http.converter.HttpMessageNotWritableException: No conve](https://blog.csdn.net/weixin_43263994/article/details/123005978)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"]
[ .reference_list ]