JSON parse error: Cannot deserialize value of type `java.lang.Integer` from Boolean value

本文档描述了一个常见的开发问题,即前端Vue应用传递的数据(布尔类型)与后端Java实体类字段(int类型)不匹配,导致更新操作失败。在后端,使用了`@RequestBody`注解的`Car`实体类接收PUT请求的数据,但前端在编辑表单时将状态设为布尔值。解决方法包括调整后端实体类字段类型或在前端将布尔值转换为整数再进行传输。

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

问题原因所在:前端Vue传输的数据字段类型和后端实体类字段不一致。
我的实体类字段是int类型。前端传输的数据是布尔类型。

1、后端方法

    @RequestMapping(value = "/car/editCar", method = RequestMethod.PUT)
    public Result updateOneUser(@RequestBody Car car) {
        int rs = carService.updateCar(car);
        if (rs > 0) {
            return Result.ok();
        } else {
            throw new BusinessException(ResultCode.UPDATE_USER_ERROR.getCode(),
                    ResultCode.UPDATE_USER_ERROR.getMessage());
        }

    }

2、实体类字段

在这里插入图片描述

报错信息

2、前端传输的数据

在这里插入图片描述

            <el-button type="primary" @click="editCar(scope.$index,scope.row)" icon="el-icon-edit" circle>编辑</el-button>

调用方法打开窗口的方法,将数据写入弹窗中

     editCar(index, row) {
        this.dialogVisible = true;//dialog对话窗口打开
        this.editForm = Object.assign({}, row);//将数据传入dialog页面
        this.editForm.index=index;//传递当前index

      },

点击弹窗form表单的提交按钮

    <el-button type="primary" @click="update('editForm')">确 定</el-button>

再次调用方法

      update(formName) {
        const _this = this;
        this.editForm.status=0  //直接设置值,
        console.log(this.editForm)
        this.$refs[formName].validate((valid) => {
          if (valid) {
            axios.put('/car/editCar',this.editForm).then(function (resp) {
              if(resp.data.code==200){
                _this.$alert('修改成功', '消息', {
                  confirmButtonText: '确定',
                  callback: action => {
                    _this.dialogVisible = false;//dialog对话窗口关闭
                    _this.showAllUsers();
                  }
                });

              }
            })
          }
        });
      },
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

乡下小哥编程

整理不易、多谢支持

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值