Skip to content

Commit a46ab04

Browse files
committed
Refactor: Use HttpStatusCode instead of magic value 200.
Signed-off-by: Mengqi Xu <[email protected]>
1 parent 63770ba commit a46ab04

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/HttpEntityMethodProcessor.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131

3232
import org.springframework.core.MethodParameter;
3333
import org.springframework.core.ResolvableType;
34+
import org.springframework.http.HttpStatusCode;
35+
import org.springframework.http.HttpStatus;
3436
import org.springframework.http.HttpEntity;
3537
import org.springframework.http.HttpHeaders;
3638
import org.springframework.http.HttpMethod;
@@ -237,17 +239,17 @@ else if (returnValue instanceof ProblemDetail detail) {
237239
}
238240

239241
if (httpEntity instanceof ResponseEntity<?> responseEntity) {
240-
int returnStatus = responseEntity.getStatusCode().value();
241-
outputMessage.getServletResponse().setStatus(returnStatus);
242-
if (returnStatus == 200) {
242+
HttpStatusCode httpStatusCode = responseEntity.getStatusCode();
243+
outputMessage.getServletResponse().setStatus(httpStatusCode.value());
244+
if (HttpStatus.OK.value() == httpStatusCode.value()) {
243245
HttpMethod method = inputMessage.getMethod();
244246
if ((HttpMethod.GET.equals(method) || HttpMethod.HEAD.equals(method))
245247
&& isResourceNotModified(inputMessage, outputMessage)) {
246248
outputMessage.flush();
247249
return;
248250
}
249251
}
250-
else if (returnStatus / 100 == 3) {
252+
else if (httpStatusCode.is3xxRedirection()) {
251253
String location = outputHeaders.getFirst("location");
252254
if (location != null) {
253255
saveFlashAttributes(mavContainer, webRequest, location);

0 commit comments

Comments
 (0)