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?
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?
You can use ResponseEntity to set the http response on each methods Example:
ResponseEntity.status(status);
you can give your status for each method with it
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.