Issue
When I use @PostMapping
, I will give a CREATED(201)
response status together by ResponseStatus
annotation. The same as @DeleteMapping
, @PutMapping
, ect.
So, is there any way to set the default response status at different requestMapping?
Solution
You can return ResponseEntity
from a method of controller as your mapping response
Example code as follows:
@GetMapping("/get")
public @ResponseBody ResponseEntity<String> get() {
return new ResponseEntity<String>("GET Response", HttpStatus.OK);
}
You can use same mechanism in @DeleteMapping
, @PutMapping
and others.
Answered By - Zico
Answer Checked By - Willingham (JavaFixing Volunteer)