解决Field error in object ‘user‘ on field ‘name‘: rejected value [Tom]问题

问题描述

使用postman传递参数,报错400。
在这里插入图片描述

400 Bad Request错误的含义
400 Bad Request错误表示服务器无法理解客户端发送的请求,原因通常是由于客户端发送的请求存在问题。

完整的报错信息如下:

Resolved [org.springframework.validation.BindException: org.springframework.validation.BeanPropertyBindingResult: 1 errors<EOL>Field error in object 'user' on field 'name': rejected value [Tom]; codes [typeMismatch.user.name,typeMismatch.name,typeMismatch.int,typeMismatch]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [user.name,name]; arguments []; default message [name]]; default message [Failed to convert property value of type 'java.lang.String' to required type 'int' for property 'name'; nested exception is java.lang.NumberFormatException: For input string: "Tom"]]

问题分析

报错400说明客户端传递参数无法正确被服务器接收,报错的重点:

  1. rejected value [Tom]; codes [typeMismatch.user.name,typeMismatch.name,typeMismatch.int,typeMismatch]
  2. Failed to convert property value of type ‘java.lang.String’ to required type ‘int’ for property ‘name’

类型不匹配,name要求int类型,服务器不会认为是自己设置有问题,会判定是客户端传递参数有问题。
回到idea找到代码,果然是int类型。

private int name;

int 类型是idea联想后直接tab生成出来的,解决方式就是把name换成String类型,重新生成getter和setter,问题解决。

相关推荐

  1. XML 解析异常问题解决

    2024-07-19 07:00:04       27 阅读
  2. Edge问题解决教程

    2024-07-19 07:00:04       56 阅读
  3. 问题解决记录-pypcd

    2024-07-19 07:00:04       56 阅读
  4. 问题解决方案

    2024-07-19 07:00:04       58 阅读
  5. 20240208问题解决

    2024-07-19 07:00:04       45 阅读
  6. 解决toFixed精度问题

    2024-07-19 07:00:04       45 阅读
  7. 解决跨域问题

    2024-07-19 07:00:04       41 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-07-19 07:00:04       67 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-07-19 07:00:04       72 阅读
  3. 在Django里面运行非项目文件

    2024-07-19 07:00:04       58 阅读
  4. Python语言-面向对象

    2024-07-19 07:00:04       69 阅读

热门阅读

  1. vite + vue3 + uniapp 项目从零搭建

    2024-07-19 07:00:04       22 阅读
  2. React中Hooks几个有用的 ref

    2024-07-19 07:00:04       19 阅读
  3. Android RecyclerView实现Item单条滑动,一屏滑动

    2024-07-19 07:00:04       17 阅读
  4. crc、ecc、 uboot和 boot的原理分析及详解

    2024-07-19 07:00:04       22 阅读
  5. React Hook 总结(React 萌新升级打怪中...)

    2024-07-19 07:00:04       21 阅读
  6. linux路由基础知识(一)

    2024-07-19 07:00:04       16 阅读
  7. Activiti7+ SpringBoot+SpringMVC 开发

    2024-07-19 07:00:04       19 阅读
  8. AWS backup服务和 RDS snapshot的关系

    2024-07-19 07:00:04       22 阅读
  9. 低代码前端框架Amis全面教程

    2024-07-19 07:00:04       17 阅读