Required String parameter '***Id' is not present. status 400

报该错误的原因不唯一,我仅在此分享我的情况。

后端接收参数代码:

@RequestMapping("data****/delete*****")
    public ResultMeta delete*****Controller(
            @RequestParam(value = "***Id") @NotNull  @NotEmpty String ***Id,
            @RequestParam(value = "***Code") @NotNull  @NotEmpty String ***Code,
            @RequestParam(value = "***GroupId",required=false) @NotNull  @NotEmpty String ***GroupId) {
        此处省略
    }

报错

{
    "timestamp": "2023-12-14T06:34:52.342+0000",
    "status": 400,
    "error": "Bad Request",
    "message": "Required String parameter '***Id' is not present",
    "path": "/data****/delete*****"
}

问题解释:

@RequestParam 注解一般用来接受查询参数和表单参数,不能用来接收 json 参数。

解决方法一:把 json 格式的参数变成表单格式,同时指定 Content-Type:

export const delete*****Api = (***Id, ***Code, ***GroupId) => {
    const formData = new URLSearchParams();
    formData.append('***Id', ***Id);
    formData.append('***Code', ***Code);
    formData.append('***GroupId', ***GroupId);
    return http.post('data****/delete****', formData, {
        headers: {
          'Content-Type': 'application/x-www-form-urlencoded',
        },
      });
}

解决方法二:把 json 格式的参数放到 post 方法的第三个参数中(再加个花括号),而不是第二个参数:


export const delete*****Api = (***Id, ***Code, ***GroupId) => {
    const params = {
        ***Id, 
        ***Code, 
        ***GroupId,
    }
    return http.post('data****/delete*****', null, { params });
}

解决方法三:后端使用 @RequestBody 而不是 @RequestParam 接收参数。
 

 

 

posted @ 2025-12-13 10:48  狗艳艳花  阅读(10)  评论(0)    收藏  举报