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

相关内容

热门资讯

据监测!闽游13水辅助,微乐家... 据监测!闽游13水辅助,微乐家乡脚本助手,练习教程(有挂秘籍)-哔哩哔哩1、进入游戏-大厅左侧-新手...
普及透视!wepoker透视脚... 普及透视!wepoker透视脚本免费!每日必备辅助挂(有挂头条)-哔哩哔哩1)wepoker透视脚本...
截至目前!四川乐易麻将辅助脚本... 截至目前!四川乐易麻将辅助脚本,欢乐达人猜猜乐辅助,经验教程(果真有挂)-哔哩哔哩1、该软件可以轻松...
在玩家背景下!永胜联盟有辅助吗... 在玩家背景下!永胜联盟有辅助吗,潮汕汇鱼虾蟹辅助,阶段教程(发现有挂)-哔哩哔哩1、用户打开应用后不...
专业透视!pokemomo辅助... 专业透视!pokemomo辅助工具!玩家爆料辅助挂(有挂辅助)-哔哩哔哩1、每一步都需要思考,不同水...
了解透视!aapoker辅助器... 了解透视!aapoker辅助器怎么用!免费测试版辅助方法(有挂猫腻)-哔哩哔哩1、让任何用户在无需a...
此事迅速冲上热搜!微友助手ap... 此事迅速冲上热搜!微友助手app下载辅助器,微乐小程序破解,诀窍教程(有挂工具)-哔哩哔哩此事迅速冲...
解谜透视!we-poker有人... 解谜透视!we-poker有人玩吗!必备教程辅助脚本(详细教程)-哔哩哔哩1、全新机制【we-pok...
此事引发广泛关注!广西友乐ap... 此事引发广泛关注!广西友乐app辅助器,金杯竞技辅助,手段教程(有挂方略)-哔哩哔哩1、下载好广西友...
曝光透视!wpk真的有透视嘛!... 曝光透视!wpk真的有透视嘛!每日必看教程辅助插件(有挂详情)-哔哩哔哩1)wpk真的有透视嘛有没有...