zoukankan      html  css  js  c++  java
  • 报错:For input string: ""

    报错具体内容如下:

     原因分析:输入空字符串,无法解析成长整形

    错误代码:

    前端

    openEditDialog(dialogStatus, titleStatus, row) {
          this.dialogTableVisible = dialogStatus;
          this.titleStatus = titleStatus;
          if (titleStatus === "create") {
            this.cleanData();
          }
          if (row) {
            this.entity = Object.assign({
              goodsCode: "",
              goodsName: "",
              goodsType: "",
              goodsSpec: "",
              packageType: "",
              goodsEngName: "",
              produceAddress: "",
              isvalid: "1",
              goodsDesc: "",
              remark: "",
              entityId: ""
            }, row);
            this.oldGoodsCode=this.entity.goodsCode;
          }
          this.$nextTick(() => {
            this.$refs["form"].clearValidate();
          })
    
        },
    cleanData() {
    this.entity = {
    goodsCode: "",
    goodsName: "",
    goodsType: "",
    goodsSpec: "",
    packageType: "",
    goodsEngName: "",
    produceAddress: "",
    isvalid: "1",
    goodsDesc: "",
    remark: "",
    entityId: ""
    }
    this.enpriseName = "";
    },
    create() {
    this.$refs['form'].validate((valid) => {
    if (valid) {
    this.submitLoading = true;
    saveGoods(this.entity).then(res => {
    if(res.success){
    this.$message.success(res.msg);
    this.$emit("getList")
    }else {
    this.$message.error(res.msg);
    }
    }).catch(() => {
    this.$message.error("新增失败")
    }).finally(() => {
    this.submitLoading = false;
    this.close();
    })
    }
    })
    },

    后台:

    @PostMapping("/saveGoods")
        @Log("添加商品")
        public Result saveGoods(@RequestBody Goods goods) throws Exception {
            return goodsService.saveGoods(goods);
    
        }

    Goods实体类中

    /**
         * 所属企业
         */
        @Column(name="entity_id")
        @JsonSerialize(using = LongJsonSerializer.class)
        @JsonDeserialize(using = LongJsonDeserializer.class)
        private Long entityId;

    当点击添加时,由于this.entity.entityId值为空字符串,后台用Long类型的entityId接收,故报错

    解决方案:前端传递entityId时将空字符串改为null。

  • 相关阅读:
    人月神话阅读笔记01
    Map Reduce数据清洗及Hive数据库操作
    Hadoop实验六——MapReduce的操作
    假期第九周学习记录
    假期第八周学习记录
    假期第七周学习记录
    hadoop不在sudoers文件中。此事将被报告。 解决方法
    假期第六周学习记录
    2021寒假(22)
    2021寒假(21)
  • 原文地址:https://www.cnblogs.com/zwh0910/p/15467536.html
Copyright © 2011-2022 走看看