diff --git a/spring-web/src/main/java/org/springframework/http/ResponseEntity.java b/spring-web/src/main/java/org/springframework/http/ResponseEntity.java index b0c1e1086b..6f0000b7d2 100644 --- a/spring-web/src/main/java/org/springframework/http/ResponseEntity.java +++ b/spring-web/src/main/java/org/springframework/http/ResponseEntity.java @@ -228,6 +228,15 @@ public class ResponseEntity extends HttpEntity { return status(HttpStatus.NO_CONTENT); } + /** + * Creates a builder with a {@link HttpStatus#BAD_REQUEST} status. + * @return the created builder + * @since 4.1 + */ + public static BodyBuilder badRequest() { + return status(HttpStatus.BAD_REQUEST); + } + /** * Creates a builder with a {@link HttpStatus#NOT_FOUND NOT_FOUND} status. * @return the created builder diff --git a/spring-web/src/test/java/org/springframework/http/ResponseEntityTests.java b/spring-web/src/test/java/org/springframework/http/ResponseEntityTests.java index 07b7828898..4703dc4488 100644 --- a/spring-web/src/test/java/org/springframework/http/ResponseEntityTests.java +++ b/spring-web/src/test/java/org/springframework/http/ResponseEntityTests.java @@ -101,6 +101,15 @@ public class ResponseEntityTests { assertNull(responseEntity.getBody()); } + @Test + public void badRequest() throws URISyntaxException { + ResponseEntity responseEntity = ResponseEntity.badRequest().build(); + + assertNotNull(responseEntity); + assertEquals(HttpStatus.BAD_REQUEST, responseEntity.getStatusCode()); + assertNull(responseEntity.getBody()); + } + @Test public void notFound() throws URISyntaxException { ResponseEntity responseEntity = ResponseEntity.notFound().build();