Field error in object ‘xxx‘ on field ‘xxx‘: rejected value [xx];

当前端传入的数据类型与后端实体或数据库定义不符时,会导致类型错误。例如,在Springboot应用中,前端输入的`price`值可能与后端实体的Integer类型冲突。解决方法包括检查数据类型转换,确保前端、后端及数据库中属性类型的一致性。如果问题依旧,需全面检查所有相关位置的类型设置。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

错误翻译:

 字段上对象“xxx”中的field错误,拒绝了值[xxx]。        

意思是:在Springboot或者springssm框架或者其他框架中编写程序时,前端传入的数据例如

 <input type="text" name="price"  class="layui-input"lay-verify="required|number">

这个price从客户端接收的值与后端entity中定义的属性值不匹配(与数据库定义的值的类型不匹配)时,就发生接收值类型错误。

解决办法:

1、看是否将基本数据类型int、double、long等转换为其对应的对象类型Integer、Double、Long等

(即实体类中定义的属性类型用其对应的对象类型,Integer

2、修改客户端的值,重新输入正确类型的值。

如果还是报错,查看程序内的该属性类型是否都一致(包括数据库,实体类,前端页面)。

Resolved [org.springframework.web.method.annotation.ModelAttributeMethodProcessor$1: org.springframework.validation.BeanPropertyBindingResult: 4 errors<EOL>Field error in object 'order' on field 'order_id': rejected value [null]; codes [typeMismatch.order.order_id,typeMismatch.order_id,typeMismatch.int,typeMismatch]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [order.order_id,order_id]; arguments []; default message [order_id]]; default message [Failed to convert value of type 'null' to required type 'int'; nested exception is org.springframework.core.convert.ConversionFailedException: Failed to convert from type [null] to type [int] for value [null]; nested exception is java.lang.IllegalArgumentException: A null value cannot be assigned to a primitive type]<EOL>Field error in object 'order' on field 'phone': rejected value [null]; codes [typeMismatch.order.phone,typeMismatch.phone,typeMismatch.int,typeMismatch]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [order.phone,phone]; arguments []; default message [phone]]; default message [Failed to convert value of type 'null' to required type 'int'; nested exception is org.springframework.core.convert.ConversionFailedException: Failed to convert from type [null] to type [int] for value [null]; nested exception is java.lang.IllegalArgumentException: A null value cannot be assigned to a primitive type]<EOL>Field error in object 'order' on field 'buy': rejected value [null]; codes [typeMismatch.order.buy,typeMismatch.buy,typeMismatch.int,typeMismatch]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [order.buy,buy]; arguments []; default message [buy]]; default message [Failed to convert value of type 'null' to required type 'int'; nested exception is org.springframework.core.convert.ConversionFailedException: Failed to convert from type [null] to type [int] for value [null]; nested exception is java.lang.IllegalArgumentException: A null value cannot be assigned to a primitive type]<EOL>Field error in object 'order' on field 'total': rejected value [null]; codes [typeMismatch.order.total,typeMismatch.total,typeMismatch.int,typeMismatch]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [order.total,total]; arguments []; default message [total]]; default message [Failed to convert value of type 'null' to required type 'int'; nested exception is org.springframework.core.convert.ConversionFailedException: Failed to convert from type [null] to type [int] for value [null]; nested excep
06-03
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值