java.lang.Object | ||
↳ | org.springframework.http.HttpEntity<T> | |
↳ | org.springframework.http.ResponseEntity<T> |
Extension of HttpEntity
that adds a HttpStatus
status code.
Returned by getForEntity(String, Class
:
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); }
[Expand]
Inherited Fields | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
org.springframework.http.HttpEntity
|
Public Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Create a new
ResponseEntity with the given status code, and no body nor headers. | |||||||||||
Create a new
ResponseEntity with the given body and status code, and no headers. | |||||||||||
Create a new
HttpEntity with the given headers and status code, and no body. | |||||||||||
Create a new
HttpEntity with the given body, headers, and status code. |
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Return the HTTP status code of the response.
|
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
org.springframework.http.HttpEntity
| |||||||||||
From class
java.lang.Object
|
Create a new ResponseEntity
with the given status code, and no body nor headers.
statusCode | the status code |
---|
Create a new ResponseEntity
with the given body and status code, and no headers.
body | the entity body |
---|---|
statusCode | the status code |
Create a new HttpEntity
with the given headers and status code, and no body.
headers | the entity headers |
---|---|
statusCode | the status code |
Create a new HttpEntity
with the given body, headers, and status code.
body | the entity body |
---|---|
headers | the entity headers |
statusCode | the status code |
Return the HTTP status code of the response.