500报错:Required String parameter 'yz00Id' is not present (必需的字符串参数“yz00Id”不存在)
看了一下,前端有给后台传 “yz00Id” 这个参数,但是好像没有识别出来,后来仔细看了一下,后台使用 @RequestParam 来接收前端传过来的参数,那么前端需要传入的是正常表单数据,有两种方法:
1、直接在链接上拼接参数
.get("getCardById?Id="+this.formObj.id)
2、使用formData格式提交
let formData = new FormData();
formData.append(this.formObj.id);
axios
.get("/getCardById",formData)
.then();
拓展:
如果后台使用 @RequestBody HashMap<String, String> map 来接收前端传过来的参数,那么前端需要传一个 json 格式的数据
json格式提交:
//let getParams = JSON.stringify(this.formMess);
let getParams = {};
getParams.id = this.formObj.id;
axios
.get("url",getParams).then();
需要注意的是,如果请求类型为delete并且参数类型不是json的话,不能使用通过表单类型提交,参数需要跟到请求url后面,并且后台使用@PathVariable
进行获取参数。