类 RequestEntity<T>


  • public class RequestEntity<T>
    extends HttpEntity<T>
    Extension of HttpEntity that adds a method and uri. Used in RestTemplate and @Controller methods.

    In RestTemplate, this class is used as parameter in exchange():

     MyRequest body = ...
     RequestEntity<MyRequest> request = RequestEntity.post(new URI("https://example.com/bar")).accept(MediaType.APPLICATION_JSON).body(body);
     ResponseEntity<MyResponse> response = template.exchange(request, MyResponse.class);
     

    If you would like to provide a URI template with variables, consider using UriTemplate:

     URI uri = new UriTemplate("https://example.com/{foo}").expand("bar");
     RequestEntity<MyRequest> request = RequestEntity.post(uri).accept(MediaType.APPLICATION_JSON).body(body);
     

    Can also be used in Spring MVC, as a parameter in a @Controller method:

     @RequestMapping("/handle")
     public void handle(RequestEntity<String> request) {
       HttpMethod method = request.getMethod();
       URI url = request.getUrl();
       String body = request.getBody();
     }
     
    从以下版本开始:
    4.1
    作者:
    Arjen Poutsma, Sebastien Deleuze
    另请参阅:
    getMethod(), getUrl()
    • 构造器详细资料

      • RequestEntity

        public RequestEntity​(HttpMethod method,
                             URI url)
        Constructor with method and URL but without body nor headers.
        参数:
        method - the method
        url - the URL
      • RequestEntity

        public RequestEntity​(T body,
                             HttpMethod method,
                             URI url)
        Constructor with method, URL and body but without headers.
        参数:
        body - the body
        method - the method
        url - the URL
      • RequestEntity

        public RequestEntity​(T body,
                             HttpMethod method,
                             URI url,
                             Type type)
        Constructor with method, URL, body and type but without headers.
        参数:
        body - the body
        method - the method
        url - the URL
        type - the type used for generic type resolution
        从以下版本开始:
        4.3
      • RequestEntity

        public RequestEntity​(T body,
                             MultiValueMap<String,​String> headers,
                             HttpMethod method,
                             URI url,
                             Type type)
        Constructor with method, URL, headers, body and type.
        参数:
        body - the body
        headers - the headers
        method - the method
        url - the URL
        type - the type used for generic type resolution
        从以下版本开始:
        4.3