|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.springframework.http.HttpEntity<T> org.springframework.http.ResponseEntity<T>
public class ResponseEntity<T>
Extension of HttpEntity
that adds a HttpStatus
status code.
Returned by RestTemplate.getForEntity(java.lang.String, java.lang.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:
Can 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()
Field Summary |
---|
Fields inherited from class org.springframework.http.HttpEntity |
---|
EMPTY |
Constructor Summary | |
---|---|
ResponseEntity(MultiValueMap<String,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<String,String> headers,
HttpStatus statusCode)
Create a new HttpEntity with the given body, headers, and status code. |
Method Summary | |
---|---|
HttpStatus |
getStatusCode()
Return the HTTP status code of the response. |
Methods inherited from class org.springframework.http.HttpEntity |
---|
getBody, getHeaders, hasBody |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public 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<String,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<String,String> headers, HttpStatus statusCode)
HttpEntity
with the given body, headers, and status code.
body
- the entity bodyheaders
- the entity headersstatusCode
- the status codeMethod Detail |
---|
public HttpStatus getStatusCode()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |