4

I'm using Spring boot 1.4.0, Consider below code in a @RestController, what I expect is, the server side will receive a http body with form_urlencoded content type, but unfortunately it demands me a query parameter type with email and token. What's the problem here and how to fix?

@DeleteMapping(consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
@ResponseStatus(HttpStatus.NO_CONTENT)
public void removeAdmin(@RequestParam(value = "email") String email, @RequestParam(value = "token") String token) {
    //...
}
July
  • 855
  • 4
  • 11
  • 22
  • The web container seems to have thrown away the body of DELETE. https://stackoverflow.com/a/2074380/1986241 – Attacktive Oct 10 '18 at 07:28

1 Answers1

3

@DeleteMapping is only a convenience extension the provides @RequestMapping(method=DELETE) It will not handle request paramters. You will still have to map those in the controllers method signature if you need the data to perform the work.

Since you want a body, You could create an object and mark it as @RequestBody:

public class DeleteBody {
    public String email;
    public String token;
}

public void removeAdmin(@RequestBody DeleteBody deleteBody) {
...
}
Bob Lukens
  • 700
  • 6
  • 10