報錯: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。

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM