Skip to content

Commit 5105793

Browse files
committed
javadoc
1 parent 689e7b7 commit 5105793

File tree

2 files changed

+24
-4
lines changed

2 files changed

+24
-4
lines changed

org.springframework.web/src/main/java/org/springframework/http/HttpEntity.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@
2323
*
2424
* <p>Typically used in combination with the {@link org.springframework.web.client.RestTemplate RestTemplate}, like so:
2525
* <pre class="code">
26-
* HttpEntity&lt;String&gt; entity = new HttpEntity&lt;String&gt;(helloWorld, MediaType.TEXT_PLAIN);
26+
* HttpHeaders headers = new HttpHeaders();
27+
* headers.setContentType(MediaType.TEXT_PLAIN);
28+
* HttpEntity&lt;String&gt; entity = new HttpEntity&lt;String&gt;(helloWorld, headers);
2729
* URI location = template.postForLocation("http://example.com", entity);
2830
* </pre>
2931
* or
@@ -33,12 +35,12 @@
3335
* MediaType contentType = entity.getHeaders().getContentType();
3436
* </pre>
3537
* Can also be used in Spring MVC, as a return value from a @Controller method:
36-
* <pre>
38+
* <pre class="code">
3739
* &#64;RequestMapping("/handle")
38-
* public HttpEntity&ltString&gt handle() {
40+
* public HttpEntity&lt;String&gt; handle() {
3941
* HttpHeaders responseHeaders = new HttpHeaders();
4042
* responseHeaders.set("MyResponseHeader", "MyValue");
41-
* return new HttpEntity<String>("Hello World", responseHeaders);
43+
* return new HttpEntity&lt;String&gt;("Hello World", responseHeaders);
4244
* }
4345
* </pre>
4446
*

org.springframework.web/src/main/java/org/springframework/http/ResponseEntity.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,24 @@
2121
/**
2222
* Extension of {@link HttpEntity} that adds a {@link HttpStatus} status code.
2323
*
24+
* <p>Returned by {@link org.springframework.web.client.RestTemplate#getForEntity}:
25+
* <pre class="code">
26+
* ResponseEntity&lt;String&gt; 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+
* &#64;RequestMapping("/handle")
35+
* public ResponseEntity&lt;String&gt; handle() {
36+
* HttpHeaders responseHeaders = new HttpHeaders();
37+
* responseHeaders.set("MyResponseHeader", "MyValue");
38+
* return new ResponseEntity&lt;String&gt;("Hello World", responseHeaders, HttpStatus.CREATED);
39+
* }
40+
* </pre>
41+
*
2442
* @author Arjen Poutsma
2543
* @since 3.0.2
2644
* @see #getStatusCode()

0 commit comments

Comments
 (0)