解决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类型。

java 复制代码
private int name;

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

相关推荐
2501_913061342 分钟前
网络原理之HTTP(3)
java·网络·网络协议·http·面试
郭涤生3 分钟前
C++ 线程同步复习
开发语言·c++
Mem0rin4 分钟前
[Java]排序
java·算法·排序算法
Full Stack Developme5 分钟前
Hutool EnumUtil 教程
开发语言·windows·python
番茄去哪了6 分钟前
JeecgBoot框架集成spring ai并进行同步调用异步调用模板
java·人工智能·spring
XMYX-07 分钟前
18 - Go 等待协程:WaitGroup 使用与坑
开发语言·golang
京师20万禁军教头9 分钟前
30面向对象(中级)-super关键字
java
feifeigo12310 分钟前
基于遗传算法的矩形排样MATLAB实现
开发语言·matlab
他是龙55114 分钟前
65:JS安全&浏览器插件&工具箱等
开发语言·javascript·安全
csbysj202014 分钟前
Rust 输出到命令行
开发语言