解决Field error in object ‘user‘ on field ‘name‘: rejected value [Tom]问题
创始人
2024-12-27 09:10:14
0

问题描述

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

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

完整的报错信息如下:

Resolved [org.springframework.validation.BindException: org.springframework.validation.BeanPropertyBindingResult: 1 errorsField 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、哈糖大菠萝有挂吗免费脚本咨...
避坑细节!微信微乐开挂,哈糖大... 避坑细节!微信微乐开挂,哈糖大菠萝开挂,阶段教程(真实有挂)-哔哩哔哩1、操作简单,无需哈糖大菠萝开...
推荐透视!pokemmo脚本辅... 推荐透视!pokemmo脚本辅助器,werplan外卦神器,大纲教程(发现有挂)-哔哩哔哩pokem...
了解透视!sohoo辅助!切实... 了解透视!sohoo辅助!切实真的有辅助教程(有挂详细)-哔哩哔哩1、起透看视 sohoo辅助辅助软...
科技介绍!新西部透视辅助,约局... 科技介绍!新西部透视辅助,约局吧是否有挂,指南书教程(揭秘有挂)-哔哩哔哩;1、约局吧是否有挂公共底...
专业透视!sohoo辅助,ep... 专业透视!sohoo辅助,epoker免费透视脚本,练习教程(了解有挂)-哔哩哔哩1、游戏颠覆性的策...
解谜透视!pokemomo辅助... 解谜透视!pokemomo辅助软件!真是是有辅助教程(今日头条)-哔哩哔哩在进入pokemomo辅助...
总结透视!哈糖大菠萝能开挂吗,... 总结透视!哈糖大菠萝能开挂吗,wepoker透视脚本视频,课程教程(有挂攻略)-哔哩哔哩暗藏猫腻,小...
技术分享!!极速官方暗堡辅助软... 技术分享!!极速官方暗堡辅助软件,aapoker怎么设置抽水,方针教程(有挂猫腻)-哔哩哔哩1、进入...
分享透视!竞技联盟辅助插件!一... 分享透视!竞技联盟辅助插件!一直是真的有辅助脚本(有挂分享)-哔哩哔哩1、下载好竞技联盟辅助插件脚本...