public class ResponseEntity<T> extends HttpEntity<T>
HttpEntity that adds a HttpStatus status code.
Returned by RestTemplate.getForEntity(java.lang.String, java.lang.Class<T>, java.lang.Object...):
ResponseEntity<String> entity = template.getForEntity("http://example.com", String.class);
String body = entity.getBody();
MediaType contentType = entity.getHeaders().getContentType();
HttpStatus statusCode = entity.getStatusCode();
Can also be used in Spring MVC, as a return value from a @Controller method:
@RequestMapping("/handle")
public ResponseEntity<String> handle() {
HttpHeaders responseHeaders = new HttpHeaders();
responseHeaders.set("MyResponseHeader", "MyValue");
return new ResponseEntity<String>("Hello World", responseHeaders, HttpStatus.CREATED);
}
getStatusCode()| Modifier and Type | Field and Description |
|---|---|
private HttpStatus |
statusCode |
EMPTY| Constructor and Description |
|---|
ResponseEntity(HttpStatus statusCode)
Create a new
ResponseEntity with the given status code, and no body nor headers. |
ResponseEntity(MultiValueMap<java.lang.String,java.lang.String> headers,
HttpStatus statusCode)
Create a new
HttpEntity with the given headers and status code, and no body. |
ResponseEntity(T body,
HttpStatus statusCode)
Create a new
ResponseEntity with the given body and status code, and no headers. |
ResponseEntity(T body,
MultiValueMap<java.lang.String,java.lang.String> headers,
HttpStatus statusCode)
Create a new
HttpEntity with the given body, headers, and status code. |
| Modifier and Type | Method and Description |
|---|---|
boolean |
equals(java.lang.Object other) |
HttpStatus |
getStatusCode()
Return the HTTP status code of the response.
|
int |
hashCode() |
java.lang.String |
toString() |
getBody, getHeaders, hasBodyprivate final HttpStatus statusCode
public ResponseEntity(HttpStatus statusCode)
ResponseEntity with the given status code, and no body nor headers.statusCode - the status codepublic ResponseEntity(T body, HttpStatus statusCode)
ResponseEntity with the given body and status code, and no headers.body - the entity bodystatusCode - the status codepublic ResponseEntity(MultiValueMap<java.lang.String,java.lang.String> headers, HttpStatus statusCode)
HttpEntity with the given headers and status code, and no body.headers - the entity headersstatusCode - the status codepublic ResponseEntity(T body, MultiValueMap<java.lang.String,java.lang.String> headers, HttpStatus statusCode)
HttpEntity with the given body, headers, and status code.body - the entity bodyheaders - the entity headersstatusCode - the status codepublic HttpStatus getStatusCode()
public boolean equals(java.lang.Object other)
equals in class HttpEntity<T>public int hashCode()
hashCode in class HttpEntity<T>public java.lang.String toString()
toString in class HttpEntity<T>