类 ResponseEntity<T>

java.lang.Object
cn.taketoday.http.HttpEntity<T>
cn.taketoday.http.ResponseEntity<T>
类型参数:
T - the body type

public class ResponseEntity<T> extends HttpEntity<T>
Extension of HttpEntity that adds a HttpStatusCode status code. Used in RestTemplate as well @Controller methods.

Can also be used in Web MVC, as the return value from a @Controller method:


 @RequestMapping("/handle")
 public ResponseEntity<String> handle() {
   URI location = ...;
   HttpHeaders responseHeaders = HttpHeaders.create();
   responseHeaders.setLocation(location);
   responseHeaders.set("MyResponseHeader", "MyValue");
   return new ResponseEntity<>("Hello World", responseHeaders, HttpStatus.CREATED);
 }
 
Or, by using a builder accessible via static methods:

 @RequestMapping("/handle")
 public ResponseEntity<String> handle() {
   URI location = ...;
   return ResponseEntity.created(location)
              .header("MyResponseHeader", "MyValue")
              .body("Hello World");
 }
 
从以下版本开始:
3.0 2020/12/6 17:06
作者:
Arjen Poutsma, Brian Clozel, Harry Yang
另请参阅:
  • 字段详细资料

    • status

      private final Object status
  • 构造器详细资料

    • ResponseEntity

      public ResponseEntity(HttpStatusCode status)
      Create a new ResponseEntity with the given status code, and no body nor headers.
      参数:
      status - the status code
    • ResponseEntity

      public ResponseEntity(@Nullable T body, HttpStatusCode status)
      Create a new ResponseEntity with the given body and status code, and no headers.
      参数:
      body - the entity body
      status - the status code
    • ResponseEntity

      public ResponseEntity(@Nullable cn.taketoday.util.MultiValueMap<String,String> headers, HttpStatusCode status)
      Create a new HttpEntity with the given headers and status code, and no body.
      参数:
      headers - the entity headers
      status - the status code
    • ResponseEntity

      public ResponseEntity(@Nullable T body, @Nullable cn.taketoday.util.MultiValueMap<String,String> headers, HttpStatusCode status)
      Create a new HttpEntity with the given body, headers, and status code.
      参数:
      body - the entity body
      headers - the entity headers
      status - the status code
    • ResponseEntity

      public ResponseEntity(@Nullable T body, @Nullable cn.taketoday.util.MultiValueMap<String,String> headers, int rawStatus)
      Create a ResponseEntity with a body, headers, and a raw status code.
      参数:
      body - the entity body
      headers - the entity headers
      rawStatus - the status code value
      从以下版本开始:
      4.0
    • ResponseEntity

      private ResponseEntity(@Nullable T body, @Nullable cn.taketoday.util.MultiValueMap<String,String> headers, Object status)
      Create a new HttpEntity with the given body, headers, and status code. Just used behind the nested builder API.
      参数:
      body - the entity body
      headers - the entity headers
      status - the status code (as HttpStatusCode or as Integer value)
  • 方法详细资料