diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/HttpEntityMethodProcessor.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/HttpEntityMethodProcessor.java index 1dcb6f94ede..c9690e1f1d5 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/HttpEntityMethodProcessor.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/HttpEntityMethodProcessor.java @@ -34,6 +34,8 @@ import org.springframework.http.HttpEntity; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpMethod; +import org.springframework.http.HttpStatus; +import org.springframework.http.HttpStatusCode; import org.springframework.http.ProblemDetail; import org.springframework.http.RequestEntity; import org.springframework.http.ResponseEntity; @@ -237,9 +239,9 @@ else if (returnValue instanceof ProblemDetail detail) { } if (httpEntity instanceof ResponseEntity responseEntity) { - int returnStatus = responseEntity.getStatusCode().value(); - outputMessage.getServletResponse().setStatus(returnStatus); - if (returnStatus == 200) { + HttpStatusCode httpStatusCode = responseEntity.getStatusCode(); + outputMessage.getServletResponse().setStatus(httpStatusCode.value()); + if (HttpStatus.OK.value() == httpStatusCode.value()) { HttpMethod method = inputMessage.getMethod(); if ((HttpMethod.GET.equals(method) || HttpMethod.HEAD.equals(method)) && isResourceNotModified(inputMessage, outputMessage)) { @@ -247,8 +249,8 @@ && isResourceNotModified(inputMessage, outputMessage)) { return; } } - else if (returnStatus / 100 == 3) { - String location = outputHeaders.getFirst("location"); + else if (httpStatusCode.is3xxRedirection()) { + String location = outputHeaders.getFirst(HttpHeaders.LOCATION); if (location != null) { saveFlashAttributes(mavContainer, webRequest, location); }