1

I am trying to update some data using $http.post method from angularjs to Spring MVC controller. But I get error as "HTTP Status 405 - Request method 'GET' not supported". My code snippets are as below :

//AngularJS Service

updateData : function(data) {
    return $http.post('updateData', data).then(
               function(response){
                 // success callback
                 return response;
               }, 
               function(response){
                 // failure callback
                 return response;
               }
    );
}

where data is as below :

data = [{ id: 1, name: 'foo' }, { id: 2, name: 'bar' },{ id: 3, name: 'baz' }];

//Spring MVC controller code

@RequestMapping(value="/updateData", method = RequestMethod.POST)
public @ResponseBody String updateData(@RequestBody Company company) throws Exception {
    // I have created POJO for company with id and name getter-setter
    // logic to update the data in db
    //System.out.println(company.getName());
    return "success";       
}

Any error in my code?

Sowmya
  • 453
  • 1
  • 5
  • 18

1 Answers1

1

Your data is an array format data = [{ id: 1, name: 'foo' }, { id: 2, name: 'bar' },{ id: 3, name: 'baz' }];. But your @RequestBody having only object. Your RequestBody should be a List. Then only it can accept

So Kindly change your code from @RequestBody Company company to @RequestBody List<Company> company. then let me know

Ramesh Rajendran
  • 37,412
  • 45
  • 153
  • 234