ResponseEntity (Spring Framework 3.2.1.RELEASE API)
Date: 2013-01-24

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<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);
       }

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

- - ### Field Summary

    - ### Fields inherited from class org.springframework.http.HttpEntity

      `EMPTY`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `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

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `boolean` | `equals(Object other)`
    `HttpStatus` | `getStatusCode()` Return the HTTP status code of the response.
    `int` | `hashCode()`
    `String` | `toString()`

    - ### Methods inherited from class org.springframework.http.HttpEntity

      `getBody, getHeaders, hasBody`

    - ### Methods inherited from class java.lang.Object

      `clone, finalize, getClass, 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

    - #### equals

          public boolean equals(Object other)

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

    - #### hashCode

          public int hashCode()

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

    - #### toString

          public String toString()

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