Required String parameter is not present error in Spring MVC Required String parameter is not present error in Spring MVC ajax ajax

Required String parameter is not present error in Spring MVC


On the server side you expect your request parameters as query strings but on client side you send a json object. To bind a json you will need to create a single class holding all your parameters and use the @RequestBody annotation instead of @RequestParam.

@RequestMapping(value = "events/add", method = RequestMethod.POST)public void addEvent(@RequestBody CommandBean commandBean){    //some code}

Here is a more detailed explanation.


I had the same issue.. I solved it by specifying the config params in the post request:

var config = {    transformRequest : angular.identity,    headers: { "Content-Type": undefined }}$http.post('/getAllData', inputData, *config*).success(function(data,status) {    $scope.loader.loading = false;})

config was the parameter I included and it started working.. Hope it helps :)


Spring Boot Code

@RequestMapping(value = "events/add", method = RequestMethod.POST)public void addEvent(@RequestParam(value = "start_date") String start_date, @RequestParam(value = "end_date") String end_date, @RequestParam(value = "text") String text, @RequestParam(value = "userId") String userId){    //some code    }

Postman Request Link to be send: Add the parameters and value using Parmas in postman and see the below request link.

http://localhost:8080/events/add?start_date=*someValue*&end_date=*someValue*&text=*someValue*&userId=*someValue*