简体   繁体   中英

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

Trying to RequestMapping a submit, but I get this error, and I really dont understand why, because I thought everyone was provided :

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();

}
}

The method upon is mapping on this method in my Controller:

@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";


}

in your code you are expecting @RequestParam(value = "idVac" , required = true)

While in JS you are sending vacancyId.setAttribute("name", "vacancyId" );

refer Spring Docs

Element Detail

value

public abstract String value

The name of the request parameter to bind to.

Default:

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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