类 ResponseEntity<T>
java.lang.Object
cn.taketoday.http.HttpEntity<T>
cn.taketoday.http.ResponseEntity<T>
- 类型参数:
T- the body type
Extension of
HttpEntity that adds a HttpStatusCode status code.
Used in RestTemplate as well @Controller methods.
Can also be used in Web MVC, as the return value from a @Controller method:
@RequestMapping("/handle")
public ResponseEntity<String> handle() {
URI location = ...;
HttpHeaders responseHeaders = HttpHeaders.create();
responseHeaders.setLocation(location);
responseHeaders.set("MyResponseHeader", "MyValue");
return new ResponseEntity<>("Hello World", responseHeaders, HttpStatus.CREATED);
}
Or, by using a builder accessible via static methods:
@RequestMapping("/handle")
public ResponseEntity<String> handle() {
URI location = ...;
return ResponseEntity.created(location)
.header("MyResponseHeader", "MyValue")
.body("Hello World");
}
- 从以下版本开始:
- 3.0 2020/12/6 17:06
- 作者:
- Arjen Poutsma, Brian Clozel, Harry Yang
- 另请参阅:
-
嵌套类概要
嵌套类修饰符和类型类说明static interfaceDefines a builder that adds a body to the response entity.private static classstatic interfaceDefines a builder that adds headers to the response entity. -
字段概要
字段从类继承的字段 cn.taketoday.http.HttpEntity
EMPTY -
构造器概要
构造器限定符构造器说明ResponseEntity(HttpStatusCode status) Create a newResponseEntitywith the given status code, and no body nor headers.ResponseEntity(cn.taketoday.util.MultiValueMap<String, String> headers, HttpStatusCode status) Create a newHttpEntitywith the given headers and status code, and no body.ResponseEntity(T body, HttpStatusCode status) Create a newResponseEntitywith the given body and status code, and no headers.ResponseEntity(T body, cn.taketoday.util.MultiValueMap<String, String> headers, int rawStatus) Create aResponseEntitywith a body, headers, and a raw status code.ResponseEntity(T body, cn.taketoday.util.MultiValueMap<String, String> headers, HttpStatusCode status) Create a newHttpEntitywith the given body, headers, and status code.privateResponseEntity(T body, cn.taketoday.util.MultiValueMap<String, String> headers, Object status) Create a newHttpEntitywith the given body, headers, and status code. -
方法概要
修饰符和类型方法说明static ResponseEntity.BodyBuilderaccepted()Create a builder with an ACCEPTED status.static ResponseEntity.BodyBuilderCreate a builder with a BAD_REQUEST status.static ResponseEntity.BodyBuilderCreate a new builder with a CREATED status and a location header set to the given URI.booleanReturn the HTTP status code of the response.intReturn the HTTP status code of the response.inthashCode()static ResponseEntity.HeadersBuilder<?>Create a builder with a NO_CONTENT status.static ResponseEntity.HeadersBuilder<?>notFound()Create a builder with a NOT_FOUND status.static ResponseEntity.HeadersBuilder<?>of(ProblemDetail body) Create a newResponseEntity.HeadersBuilderwith its status set toProblemDetail.getStatus()and its body is set toProblemDetail.static <T> ResponseEntity<T>A shortcut for creating aResponseEntitywith the given body and the OK status, or an empty body and a NOT FOUND status in case of an Optional.empty() parameter.static ResponseEntity.BodyBuilderok()Create a builder with the status set to OK.static <T> ResponseEntity<T>ok(T body) A shortcut for creating aResponseEntitywith the given body and the status set to OK.static ResponseEntity.BodyBuilderstatus(int status) Create a builder with the given status.static ResponseEntity.BodyBuilderstatus(HttpStatusCode status) Create a builder with the given status.toString()static ResponseEntity.BodyBuilderCreate a builder with an UNPROCESSABLE_ENTITY status.从类继承的方法 cn.taketoday.http.HttpEntity
getBody, getHeaders, hasBody
-
字段详细资料
-
status
-
-
构造器详细资料
-
ResponseEntity
Create a newResponseEntitywith the given status code, and no body nor headers.- 参数:
status- the status code
-
ResponseEntity
Create a newResponseEntitywith the given body and status code, and no headers.- 参数:
body- the entity bodystatus- the status code
-
ResponseEntity
public ResponseEntity(@Nullable cn.taketoday.util.MultiValueMap<String, String> headers, HttpStatusCode status) Create a newHttpEntitywith the given headers and status code, and no body.- 参数:
headers- the entity headersstatus- the status code
-
ResponseEntity
public ResponseEntity(@Nullable T body, @Nullable cn.taketoday.util.MultiValueMap<String, String> headers, HttpStatusCode status) Create a newHttpEntitywith the given body, headers, and status code.- 参数:
body- the entity bodyheaders- the entity headersstatus- the status code
-
ResponseEntity
public ResponseEntity(@Nullable T body, @Nullable cn.taketoday.util.MultiValueMap<String, String> headers, int rawStatus) Create aResponseEntitywith a body, headers, and a raw status code.- 参数:
body- the entity bodyheaders- the entity headersrawStatus- the status code value- 从以下版本开始:
- 4.0
-
ResponseEntity
private ResponseEntity(@Nullable T body, @Nullable cn.taketoday.util.MultiValueMap<String, String> headers, Object status) Create a newHttpEntitywith the given body, headers, and status code. Just used behind the nested builder API.- 参数:
body- the entity bodyheaders- the entity headersstatus- the status code (asHttpStatusCodeor asIntegervalue)
-
-
方法详细资料
-
getStatusCode
Return the HTTP status code of the response.- 返回:
- the HTTP status as an HttpStatusCode enum entry
-
getStatusCodeValue
public int getStatusCodeValue()Return the HTTP status code of the response.- 返回:
- the HTTP status as an int value
-
equals
- 覆盖:
equals在类中HttpEntity<T>
-
hashCode
public int hashCode()- 覆盖:
hashCode在类中HttpEntity<T>
-
toString
- 覆盖:
toString在类中HttpEntity<T>
-
status
Create a builder with the given status.- 参数:
status- the response status- 返回:
- the created builder
-
status
Create a builder with the given status.- 参数:
status- the response status- 返回:
- the created builder
-
ok
Create a builder with the status set to OK.- 返回:
- the created builder
-
ok
A shortcut for creating aResponseEntitywith the given body and the status set to OK.- 返回:
- the created
ResponseEntity
-
of
A shortcut for creating aResponseEntitywith the given body and the OK status, or an empty body and a NOT FOUND status in case of an Optional.empty() parameter.- 返回:
- the created
ResponseEntity
-
of
Create a newResponseEntity.HeadersBuilderwith its status set toProblemDetail.getStatus()and its body is set toProblemDetail.Note: If there are no headers to add, there is usually no need to create a
ResponseEntitysinceProblemDetailis also supported as a return value from controller methods.- 参数:
body- the problem detail to use- 返回:
- the created builder
- 从以下版本开始:
- 4.0
-
created
Create a new builder with a CREATED status and a location header set to the given URI.- 参数:
location- the location URI- 返回:
- the created builder
-
accepted
Create a builder with an ACCEPTED status.- 返回:
- the created builder
-
noContent
Create a builder with a NO_CONTENT status.- 返回:
- the created builder
-
badRequest
Create a builder with a BAD_REQUEST status.- 返回:
- the created builder
-
notFound
Create a builder with a NOT_FOUND status.- 返回:
- the created builder
-
unprocessableEntity
Create a builder with an UNPROCESSABLE_ENTITY status.- 返回:
- the created builder
-