解决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,问题解决。

相关推荐
石一峰6996 分钟前
C 语言函数设计模式实战经验
c语言·开发语言·设计模式
sitellla12 分钟前
Pydub:用 Python 处理音频,不写废话
开发语言·python·其他·音视频
瀚高PG实验室17 分钟前
java中间件无法连接数据库
java·数据库·中间件·瀚高数据库
东南门吹雪20 分钟前
JAVA TCP socket编程框架
java·高并发·socket·tcp·nio
xingyuzhisuan20 分钟前
缓存命中率提升方案:从 30% 优化至 82% 全流程优化记录
java·开发语言·缓存·ai
郑洁文26 分钟前
基于Python的恶意流量监测系统的设计与实现
开发语言·python
AI玫瑰助手28 分钟前
Python流程控制:for循环与range函数的搭配使用
开发语言·python·信息可视化
一条泥憨鱼31 分钟前
Java开发效率神器:Lombok从入门到精通!
java·后端·学习·开发·lombok
anew___31 分钟前
2026年Python爬虫技术完全指南:从入门到实战
开发语言·爬虫·python
Jinkxs32 分钟前
Python基础 - 初识内置函数 Python自带的便捷工具
android·java·python