T
- ボディ型 public class ResponseEntity<T> extends HttpEntity<T>
HttpStatus
ステータスコードを追加する HttpEntity
の拡張。RestTemplate
および @Controller
メソッドで使用されます。RestTemplate
では、このクラスは getForEntity()
および exchange()
によって返されます。
ResponseEntity<String> entity = template.getForEntity("https://example.com", String.class); String body = entity.getBody(); MediaType contentType = entity.getHeaders().getContentType(); HttpStatus statusCode = entity.getStatusCode();
これは、@Controller
メソッドからの戻り値として Spring MVC で使用することもできます。
@RequestMapping("/handle") public ResponseEntity<String> handle() { URI location = ...; HttpHeaders responseHeaders = new HttpHeaders(); responseHeaders.setLocation(location); responseHeaders.set("MyResponseHeader", "MyValue"); return new ResponseEntity<String>("Hello World", responseHeaders, HttpStatus.CREATED); }または、静的メソッドを介してアクセス可能なビルダーを使用して:
@RequestMapping("/handle") public ResponseEntity<String> handle() { URI location = ...; return ResponseEntity.created(location).header("MyResponseHeader", "MyValue").body("Hello World"); }
getStatusCode()
, RestOperations.getForEntity(String, Class, Object...)
, RestOperations.getForEntity(String, Class, java.util.Map)
, RestOperations.getForEntity(URI, Class)
, RequestEntity
修飾子と型 | クラスと説明 |
---|---|
static interface | ResponseEntity.BodyBuilder レスポンスエンティティに本文を追加するビルダーを定義します。 |
static interface | ResponseEntity.HeadersBuilder<B extends ResponseEntity.HeadersBuilder<B>> レスポンスエンティティにヘッダーを追加するビルダーを定義します。 |
EMPTY
コンストラクターと説明 |
---|
ResponseEntity(HttpStatus status) ステータスコードのみを使用して ResponseEntity を作成します。 |
ResponseEntity(MultiValueMap<StringSE, StringSE> headers, HttpStatus status) ヘッダーとステータスコードを使用して ResponseEntity を作成します。 |
ResponseEntity(T body, HttpStatus status) 本文とステータスコードを使用して ResponseEntity を作成します。 |
ResponseEntity(T body, MultiValueMap<StringSE, StringSE> headers, HttpStatus status) 本文、ヘッダー、ステータスコードを使用して ResponseEntity を作成します。 |
ResponseEntity(T body, MultiValueMap<StringSE, StringSE> headers, int rawStatus) 本文、ヘッダー、生のステータスコードを使用して ResponseEntity を作成します。 |
修飾子と型 | メソッドと説明 |
---|---|
static ResponseEntity.BodyBuilder | accepted() ACCEPTED ステータスのビルダーを作成します。 |
static ResponseEntity.BodyBuilder | badRequest() BAD_REQUEST ステータスのビルダーを作成します。 |
static ResponseEntity.BodyBuilder | created(URISE location) CREATED ステータスおよび指定された URI に設定された場所ヘッダーを使用して、新しいビルダーを作成します。 |
boolean | equals(ObjectSE other) |
HttpStatus | getStatusCode() レスポンスの HTTP ステータスコードを返します。 |
int | getStatusCodeValue() レスポンスの HTTP ステータスコードを返します。 |
int | hashCode() |
static ResponseEntity.BodyBuilder | internalServerError() INTERNAL_SERVER_ERROR ステータスのビルダーを作成します。 |
static ResponseEntity.HeadersBuilder<?> | noContent() NO_CONTENT ステータスのビルダーを作成します。 |
static ResponseEntity.HeadersBuilder<?> | notFound() NOT_FOUND ステータスのビルダーを作成します。 |
static <T> ResponseEntity<T> | of(OptionalSE<T> body) 指定された本体と OK ステータスで ResponseEntity を作成するためのショートカット、または Optional.empty()SE パラメーターの場合は空の本体と NOT FOUND ステータスを作成するためのショートカット。 |
static ResponseEntity.BodyBuilder | ok() ステータスを OK に設定してビルダーを作成します。 |
static <T> ResponseEntity<T> | ok(T body) 指定された本体とステータスが OK に設定された ResponseEntity を作成するためのショートカット。 |
static ResponseEntity.BodyBuilder | status(HttpStatus status) 指定されたステータスでビルダーを作成します。 |
static ResponseEntity.BodyBuilder | status(int status) 指定されたステータスでビルダーを作成します。 |
StringSE | toString() |
static ResponseEntity.BodyBuilder | unprocessableEntity() UNPROCESSABLE_ENTITY ステータスのビルダーを作成します。 |
getBody, getHeaders, hasBody
cloneSE, finalizeSE, getClassSE, notifySE, notifyAllSE, waitSE, waitSE, waitSE
public ResponseEntity(HttpStatus status)
ResponseEntity
を作成します。status
- ステータスコード public ResponseEntity(@Nullable T body, HttpStatus status)
ResponseEntity
を作成します。body
- エンティティ本体 status
- ステータスコード public ResponseEntity(MultiValueMap<StringSE,StringSE> headers, HttpStatus status)
ResponseEntity
を作成します。headers
- エンティティヘッダー status
- ステータスコード public ResponseEntity(@Nullable T body, @Nullable MultiValueMap<StringSE,StringSE> headers, HttpStatus status)
ResponseEntity
を作成します。body
- エンティティ本体 headers
- エンティティヘッダー status
- ステータスコード public HttpStatus getStatusCode()
public int getStatusCodeValue()
public boolean equals(@Nullable ObjectSE other)
HttpEntity<T>
の equals
public int hashCode()
HttpEntity<T>
の hashCode
public StringSE toString()
HttpEntity<T>
の toString
public static ResponseEntity.BodyBuilder status(HttpStatus status)
status
- レスポンスステータス public static ResponseEntity.BodyBuilder status(int status)
status
- レスポンスステータス public static ResponseEntity.BodyBuilder ok()
public static <T> ResponseEntity<T> ok(@Nullable T body)
ResponseEntity
を作成するためのショートカット。body
- レスポンスエンティティの本体 (空の可能性あり)ResponseEntity
public static <T> ResponseEntity<T> of(OptionalSE<T> body)
ResponseEntity
を作成するためのショートカット、または Optional.empty()SE パラメーターの場合は空の本体と NOT FOUND ステータスを作成するためのショートカット。ResponseEntity
public static ResponseEntity.BodyBuilder created(URISE location)
location
- ロケーション URIpublic static ResponseEntity.BodyBuilder accepted()
public static ResponseEntity.HeadersBuilder<?> noContent()
public static ResponseEntity.BodyBuilder badRequest()
public static ResponseEntity.HeadersBuilder<?> notFound()
public static ResponseEntity.BodyBuilder unprocessableEntity()
public static ResponseEntity.BodyBuilder internalServerError()