Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.springframework.http
Class ResponseEntity<T>

    java.lang.Object
      org.springframework.http.HttpEntity<T>
          org.springframework.http.ResponseEntity<T>

    public class ResponseEntity<T>

extends HttpEntity<T>

Extension of `HttpEntity` that adds a `HttpStatus` status code.

Returned by `RestTemplate.getForEntity(java.lang.String, java.lang.Class, 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);
     }

Since:
  3.0.2
Author:
  Arjen Poutsma
See Also:
  `getStatusCode()`

Field Summary

Fields inherited from class org.springframework.http.HttpEntity
`EMPTY`

Constructor Summary
`ResponseEntity(HttpStatus statusCode)` Create a new `ResponseEntity` with the given status code, and no body nor headers.
`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.
`String` | `toString()`

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, wait, wait, wait`

Constructor Detail

### ResponseEntity

    public ResponseEntity(HttpStatus statusCode)

  Create a new `ResponseEntity` with the given status code, and no body nor headers.

  Parameters:
    `statusCode` - the status code

### ResponseEntity

    public ResponseEntity(T body,
                          HttpStatus statusCode)

  Create a new `ResponseEntity` with the given body and status code, and no headers.

  Parameters:
    `body` - the entity body
    `statusCode` - the status code

### ResponseEntity

    public ResponseEntity(MultiValueMap<String,String> headers,
                          HttpStatus statusCode)

  Create a new `HttpEntity` with the given headers and status code, and no body.

  Parameters:
    `headers` - the entity headers
    `statusCode` - the status code

### ResponseEntity

    public ResponseEntity(T body,
                          MultiValueMap<String,String> headers,
                          HttpStatus statusCode)

  Create a new `HttpEntity` with the given body, headers, and status code.

  Parameters:
    `body` - the entity body
    `headers` - the entity headers
    `statusCode` - the status code

Method Detail

### getStatusCode

    public HttpStatus getStatusCode()

  Return the HTTP status code of the response.

  Returns:
    the HTTP status as an HttpStatus enum value

### toString

    public String toString()

  Overrides:
    `toString` in class `HttpEntity<T>`

Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD