Annotation Interface ResponseStatus
value() and
reason() that should be returned.
The status code is applied to the HTTP response when the handler
method is invoked and overrides status information set by other means,
like ResponseEntity or "redirect:".
Warning: when using this annotation on an exception
class, or when setting the reason attribute of this annotation,
the RequestContext.sendError method will be used.
With RequestContext.sendError, the response is considered
complete and should not be written to any further. Furthermore, the Servlet
container will typically write an HTML error page therefore making the
use of a reason unsuitable for REST APIs. For such cases it is
preferable to use a ResponseEntity as
a return type and avoid the use of @ResponseStatus altogether.
Note that a controller class may also be annotated with
@ResponseStatus and is then inherited by all @RequestMapping
methods.
- 从以下版本开始:
- 2018-12-08 15:10
- 作者:
- Arjen Poutsma, Sam Brannen, Harry Yang
-
可选元素概要
可选元素修饰符和类型可选元素说明The status code to use for the response.The reason to be used for the response.Alias forcode().
-
元素详细资料
-
value
Alias forcode().- 默认值:
- INTERNAL_SERVER_ERROR
-
code
The status code to use for the response.Default is
HttpStatus.INTERNAL_SERVER_ERROR, which should typically be changed to something more appropriate.- 从以下版本开始:
- 3.0
- 另请参阅:
- 默认值:
- INTERNAL_SERVER_ERROR
-
reason
String reasonThe reason to be used for the response.Defaults to an empty string which will be ignored. Set the reason to a non-empty value to have it used to send a Servlet container error page. In this case, the return value of the handler method will be ignored.
- 从以下版本开始:
- 3.0
- 另请参阅:
- 默认值:
- ""
-