1
1
/*
2
- * Copyright 2002-2020 the original author or authors.
2
+ * Copyright 2002-2021 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
31
31
import org .springframework .util .ObjectUtils ;
32
32
33
33
/**
34
- * Extension of {@link HttpEntity} that adds a {@link HttpStatus} status code.
35
- * Used in {@code RestTemplate} as well {@code @Controller} methods.
34
+ * Extension of {@link HttpEntity} that adds an {@link HttpStatus} status code.
35
+ * Used in {@code RestTemplate} as well as in {@code @Controller} methods.
36
36
*
37
37
* <p>In {@code RestTemplate}, this class is returned by
38
38
* {@link org.springframework.web.client.RestTemplate#getForEntity getForEntity()} and
44
44
* HttpStatus statusCode = entity.getStatusCode();
45
45
* </pre>
46
46
*
47
- * <p>Can also be used in Spring MVC, as the return value from a @Controller method:
47
+ * <p>This can also be used in Spring MVC as the return value from an
48
+ * {@code @Controller} method:
48
49
* <pre class="code">
49
50
* @RequestMapping("/handle")
50
51
* public ResponseEntity<String> handle() {
@@ -81,15 +82,15 @@ public class ResponseEntity<T> extends HttpEntity<T> {
81
82
82
83
83
84
/**
84
- * Create a new {@code ResponseEntity} with the given status code, and no body nor headers .
85
+ * Create a {@code ResponseEntity} with a status code only .
85
86
* @param status the status code
86
87
*/
87
88
public ResponseEntity (HttpStatus status ) {
88
89
this (null , null , status );
89
90
}
90
91
91
92
/**
92
- * Create a new {@code ResponseEntity} with the given body and status code, and no headers .
93
+ * Create a {@code ResponseEntity} with a body and status code.
93
94
* @param body the entity body
94
95
* @param status the status code
95
96
*/
@@ -98,7 +99,7 @@ public ResponseEntity(@Nullable T body, HttpStatus status) {
98
99
}
99
100
100
101
/**
101
- * Create a new {@code HttpEntity } with the given headers and status code, and no body .
102
+ * Create a {@code ResponseEntity } with headers and a status code.
102
103
* @param headers the entity headers
103
104
* @param status the status code
104
105
*/
@@ -107,7 +108,7 @@ public ResponseEntity(MultiValueMap<String, String> headers, HttpStatus status)
107
108
}
108
109
109
110
/**
110
- * Create a new {@code HttpEntity } with the given body, headers, and status code.
111
+ * Create a {@code ResponseEntity } with a body, headers, and a status code.
111
112
* @param body the entity body
112
113
* @param headers the entity headers
113
114
* @param status the status code
@@ -119,7 +120,7 @@ public ResponseEntity(@Nullable T body, @Nullable MultiValueMap<String, String>
119
120
}
120
121
121
122
/**
122
- * Create a new {@code HttpEntity } with the given body, headers, and status code.
123
+ * Create a {@code ResponseEntity } with the given body, headers, and status code.
123
124
* Just used behind the nested builder API.
124
125
* @param body the entity body
125
126
* @param headers the entity headers
@@ -231,12 +232,13 @@ public static BodyBuilder ok() {
231
232
}
232
233
233
234
/**
234
- * A shortcut for creating a {@code ResponseEntity} with the given body and
235
- * the status set to {@linkplain HttpStatus#OK OK}.
235
+ * A shortcut for creating a {@code ResponseEntity} with the given body
236
+ * and the status set to {@linkplain HttpStatus#OK OK}.
237
+ * @param body the body of the response entity (possibly empty)
236
238
* @return the created {@code ResponseEntity}
237
239
* @since 4.1
238
240
*/
239
- public static <T > ResponseEntity <T > ok (T body ) {
241
+ public static <T > ResponseEntity <T > ok (@ Nullable T body ) {
240
242
return ok ().body (body );
241
243
}
242
244
0 commit comments