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

相关内容

热门资讯

wepoke辅助插件!wepo... wepoke辅助插件!wepoke软件免费版(WePoKe黑科技)真是是真的有挂(详细教程)-哔哩哔...
科普"aapoker... 科普"aapoker发牌机制"aapoker俱乐部后台可以操作吗(其实存在有挂)-哔哩哔哩1、很好的...
一分钟揭秘!微扑克有假吗,微扑... 一分钟揭秘!微扑克有假吗,微扑克ai机器人(微扑克)竟然有挂(的确有挂)-哔哩哔哩一、微扑克ai机器...
必知教程(德州ai辅助)德州之... 德州之星透牌器赢率提升策略‌;必知教程(德州ai辅助)德州之星透牌器(一直是真的有挂)-哔哩哔哩;详...
我来教教大家!微扑克的辅助工具... 我来教教大家!微扑克的辅助工具苹果,微扑克ai机器人(微扑克)一贯是真的有挂(真实有挂)-哔哩哔哩;...
wPk最新黑科技!wpk微扑克... wPk最新黑科技!wpk微扑克系统发牌规律(WPK ai辅助)都是有挂(2021已更新)(哔哩哔哩)...
wepokeai代打!wepo... wepokeai代打!wepokeai代打的胜率(WePoKe黑科技)确实是真的有挂(有挂透视)-哔...
揭秘"aapoker... 揭秘"aapokerai辅助"aapoker是正规的吗(总是真的是有挂)-哔哩哔哩1.aapoker...
总算了解!微扑克有挂么,微扑克... 总算了解!微扑克有挂么,微扑克ai机器人(微扑克)一直有挂(有挂透视)-哔哩哔哩1、微扑克ai机器人...
总算明白(德州ai辅助)德州之... 总算明白(德州ai辅助)德州之星外挂(本来真的是有挂)-哔哩哔哩是一款可以让一直输的玩家,快速成为一...