Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How use PUT method in Springboot Restcontroller?

Am developing an application using Spring boot.I tried with all representations verbs like GET, POST , DELETE all are working fine too. By using PUT method, it's not supporting in spring boot. Whether I need to add any new configuration.

Put method works only the request not have any parameters. If i add any query parameter or form data it doesnt work. Kindly any expertize will help me to solve this issue.

@RequestMapping("/student/info")
@RequestMapping(method = RequestMethod.PUT)
public @ResponseBody String updateStudent(@RequestParam(value = "stdName")String stdName){
    LOG.info(stdName);
    return "ok";
}

Request method 'PUT' not supported

like image 596
Aravind Cheekkallur Avatar asked Oct 29 '14 08:10

Aravind Cheekkallur


2 Answers

This code will work fine. You must specify request mapping in class level or in function level.

@RequestMapping(value = "/student/info", method = RequestMethod.PUT)
public @ResponseBody String updateStudent(@RequestBody Student student){
 LOG.info(student.toString());
 return "ok";
}
like image 112
Pratheesh Avatar answered Nov 11 '22 19:11

Pratheesh


Have you tried the following Request Mapping:

@RequestMapping(value = "/student/info", method = RequestMethod.PUT)

There's no need to separate the value and the Request Method for the URI.

like image 30
blackpanther Avatar answered Nov 11 '22 17:11

blackpanther