繁体   English   中英

发生意外错误(类型=错误的请求,状态= 400),缺少参数?

[英]There was an unexpected error (type=Bad Request, status=400), missing parameter?

尝试RequestMapping提交,但出现此错误,我真的不明白为什么,因为我认为每个人都被提供了:

There was an unexpected error (type=Bad Request, status=400).
Required Integer parameter 'idVac' is not present

[...]

function deleteRecord(idVac) {

var newwindow;
newwindow=window.confirm("Are you sure");
if(newwindow == true) {
    alert("Condition is true");
    var form = document.createElement("form");
    form.setAttribute("name", "form");
    form.setAttribute("method", "post");
    form.setAttribute("action", "/vacEditDelete");
    var vacancyId = document.createElement("input");
    vacancyId.setAttribute("type", "hidden");
    vacancyId.setAttribute("name", "vacancyId");
    vacancyId.setAttribute("value", idVac);

    var csrf = document.createElement("input");
    csrf.setAttribute("type", "hidden");
    csrf.setAttribute("name", "${_csrf.parameterName}");
    csrf.setAttribute("value", "${_csrf.token}");
    form.appendChild(csrf);

    document.body.appendChild(form);
    form.submit();

}
}

上的方法正在我的控制器中映射到此方法:

@RequestMapping(value = "/vacEditDelete", method = RequestMethod.POST)
public String deleteVacancy(@AuthenticationPrincipal User currentuser,
                            @RequestParam(value = "idVac", required = true) Integer idVac){
    System.out.println("Method called");
    vacService.deleteVacancyByID(idVac);

    return "redirect:/vacEdit";


}

在您的代码中,您期望@RequestParam(value = “ idVac” ,required = true)

在JS中,您正在发送vacancyId.setAttribute(“ name”, “ vacancyId” );

参考Spring Docs

元素细节

value

public abstract String value

The name of the request parameter to bind to.

Default:

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM