Med Med - 3 months ago 22
AngularJS Question

Required String parameter 'licenceplate' is not present"

I checked in different existing questions that was asked for similar problem but I didn't get any help for my problem.
In fact I can't use @RequestBody like in this question or this one.

I'm trying to pas some parameters from Angular controller to a Spring MVC controller, but I'm getting this error message

errorCode:500
message:"Required String parameter 'licenceplate' is not present"

here is my Angular Service:

myApp.httpEnterVehicle = function(levelNumber, placeNumber, licenceplate, placeType) {
return $http.put("/myApp/rest/vehicle/entervehicle", {
params : {
'licenceplate' : licenceplate,
'placeType' : placeType,
'placeNumber' : placeNumber,
'levelNumber' : levelNumber
},
});
};


and nothing was detected on my backend side wich seems to be strange

@RequestMapping(value = "/entervehicle", method = RequestMethod.PUT)
public ResponseEntity<Void> enterNewVehicle(@RequestParam("licenceplate") String licenceplate, @RequestParam("placeType") String placeType, @RequestParam("levelNumber") int levelNumber, @RequestParam("placeNumber") int placeNumber){
....
}


do you have any idea what's going on? I already tried toc check the content of my Angular service param and they are correct :(

Answer

You have incorrect put request call, it should look like below

$http.put('url', //1st parameter
   {}, //request body
   {} //request configuration here
);

If you compare you current put call you can see what wrong thing you were doing. You just need to pass {}(empty object) in request body the pass your config object in place of request body

myApp.httpEnterVehicle = function(levelNumber, placeNumber, licenceplate, placeType) {
    return $http.put("/myApp/rest/vehicle/entervehicle",
      {}, //added blank object as request body
      {
        params : {
            'licenceplate' : licenceplate,
            'placeType' : placeType, 
            'placeNumber' : placeNumber, 
            'levelNumber' : levelNumber
        },
    });
};