1

I tried to create some code :

@RequestMapping(value = "/testing", method = RequestMethod.POST) public ResponseEntity<Object> testing(@RequestParam(value = "requestId", required = true) String requestId){ return new ResponseEntity<Object>(requestId, HttpStatus.OK); } 

And I test that service using postman the response is success, no issue But when I change the RequestMethod to DELETE

 @RequestMapping(value = "/testing", method = RequestMethod.DELETE) public ResponseEntity<Object> testing(@RequestParam(value = "requestId", required = true) String requestId){ return new ResponseEntity<Object>(requestId, HttpStatus.OK); } 

Response of that service is error :

{ "trace": "org.springframework.web.bind.MissingServletRequestParameterException: Required String parameter 'requestId' is not present\r\n\tat org.springframework.web.method.annotation.RequestParamMethodArgumentResolver.handleMissingValue(RequestParamMethodArgumentResolver.java:204)\r\n\tat org.springframework.web.method.annotation.AbstractNamedValueMethodArgumentResolver.resolveArgument(AbstractNamedValueMethodArgumentResolver.java:112)\r\n\tat org.springframework.web.method.support.HandlerMethodArgumentResolverComposite.resolveArgument 

I set the requestId on body (form-data) same like i did when i call the POST method. I only change the RequestMethod from POST to DELETE, any idea for this case?

2
  • RequestParam extracts the value from URI, not the body form-data Commented Jul 12, 2021 at 13:40
  • ya, but in this case, i want to use form-data as request. any other suggest? Commented Jul 12, 2021 at 13:54

1 Answer 1

1

On delete method body data could be ignored. You can try requestId variable on path.

@RequestMapping(value = "/testing/{requestId}", method = RequestMethod.DELETE) public ResponseEntity<Object> testing(@PathVariable String requestId){ return new ResponseEntity<Object>(requestId, HttpStatus.OK); } 

You can check this link

Sign up to request clarification or add additional context in comments.

3 Comments

hi, thanks for your suggest, and if i used the params for requestid, the result success. but in this case, i want to use form-data as request. any other suggest?
form data(tag) only can be used with GET or POST HTTP request. maybe you can use some detour with hidden input tag. And check hidden value on every request. <form id="form" action="/testing" method="POST" > <input type="hidden" name="_method" value="DELETE"/> </form>
i have same issue when we used method GET

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.