报错具体内容如下:
原因分析:输入空字符串,无法解析成长整形
错误代码:
前端
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。