File tree Expand file tree Collapse file tree 2 files changed +24
-4
lines changed
org.springframework.web/src/main/java/org/springframework/http Expand file tree Collapse file tree 2 files changed +24
-4
lines changed Original file line number Diff line number Diff line change 23
23
*
24
24
* <p>Typically used in combination with the {@link org.springframework.web.client.RestTemplate RestTemplate}, like so:
25
25
* <pre class="code">
26
- * HttpEntity<String> entity = new HttpEntity<String>(helloWorld, MediaType.TEXT_PLAIN);
26
+ * HttpHeaders headers = new HttpHeaders();
27
+ * headers.setContentType(MediaType.TEXT_PLAIN);
28
+ * HttpEntity<String> entity = new HttpEntity<String>(helloWorld, headers);
27
29
* URI location = template.postForLocation("http://example.com", entity);
28
30
* </pre>
29
31
* or
33
35
* MediaType contentType = entity.getHeaders().getContentType();
34
36
* </pre>
35
37
* Can also be used in Spring MVC, as a return value from a @Controller method:
36
- * <pre>
38
+ * <pre class="code" >
37
39
* @RequestMapping("/handle")
38
- * public HttpEntity<String > handle() {
40
+ * public HttpEntity<String > handle() {
39
41
* HttpHeaders responseHeaders = new HttpHeaders();
40
42
* responseHeaders.set("MyResponseHeader", "MyValue");
41
- * return new HttpEntity< String> ("Hello World", responseHeaders);
43
+ * return new HttpEntity< String> ("Hello World", responseHeaders);
42
44
* }
43
45
* </pre>
44
46
*
Original file line number Diff line number Diff line change 21
21
/**
22
22
* Extension of {@link HttpEntity} that adds a {@link HttpStatus} status code.
23
23
*
24
+ * <p>Returned by {@link org.springframework.web.client.RestTemplate#getForEntity}:
25
+ * <pre class="code">
26
+ * ResponseEntity<String> entity = template.getForEntity("http://example.com", String.class);
27
+ * String body = entity.getBody();
28
+ * MediaType contentType = entity.getHeaders().getContentType();
29
+ * HttpStatus statusCode = entity.getStatusCode();
30
+ * </pre>
31
+ * Can also be used in Spring MVC, as a return value from a @Controller method:
32
+ * <p>Can be used in Spring MVC, as a return value from a @Controller method:
33
+ * <pre class="code">
34
+ * @RequestMapping("/handle")
35
+ * public ResponseEntity<String> handle() {
36
+ * HttpHeaders responseHeaders = new HttpHeaders();
37
+ * responseHeaders.set("MyResponseHeader", "MyValue");
38
+ * return new ResponseEntity<String>("Hello World", responseHeaders, HttpStatus.CREATED);
39
+ * }
40
+ * </pre>
41
+ *
24
42
* @author Arjen Poutsma
25
43
* @since 3.0.2
26
44
* @see #getStatusCode()
You can’t perform that action at this time.
0 commit comments