majed ben ali
majed ben ali

Reputation: 31

Request method 'PUT' not supported

I'm working with springboot angularsjs and restful.

my rest controller

@RequestMapping(value="/updatestructure/{ch}",method = RequestMethod.PUT)
public @ResponseBody Structurenotification updateStructure(@PathVariable(value="ch") StructureNotificationDto ch) {
    return StructureNotif.update(ch);
}

the button

$scope.addstructure = function() {
      $http.put('/structure/updatestructure/', $scope.element);
};

But I get this problem :

o.s.web.servlet.PageNotFound: Request method 'PUT' not supported

Upvotes: 1

Views: 4953

Answers (1)

Tomasz Białecki
Tomasz Białecki

Reputation: 1111

You have defined your {ch} variable as PathVariable, and you send it as Request Body. You Mapping accepts URL's like /structure/updatestructure/abc,/structure/updatestructure/efg, and values abc and efg would be than passed as strings. In this case your mapping should look like this.

@RequestMapping(value="/updatestructure/{ch}",method = RequestMethod.PUT)
public @ResponseBody Structurenotification updateStructure(@PathVariable String ch) {    
}

But, your are actualli going to send a JSON as request body(assuming from your angular $http.put(url,data)). Your mapping should be then as follows:

@RequestMapping(value="/updatestructure/",method = RequestMethod.PUT)
public @ResponseBody Structurenotification updateStructure(@RequestBody StructureNotificationDto ch) {
    return StructureNotif.update(ch);
}

Upvotes: 5

Related Questions