Java-Class-C:org.springframework.http.ResponseEntity
ylbtech-Java-Class-C:org.springframework.http.ResponseEntity |
1.返回顶部 |
Class ResponseEntity<T>
- java.lang.Object
- org.springframework.http.HttpEntity<T>
- org.springframework.http.ResponseEntity<T>
- Type Parameters:
T
- the body type
public class ResponseEntity<T>
extends HttpEntity<T>Extension ofHttpEntity
that adds aHttpStatus
status code. Used inRestTemplate
as well@Controller
methods.In
RestTemplate
, this class is returned bygetForEntity()
andexchange()
:ResponseEntity<String> entity = template.getForEntity("https://example.com", String.class);
String body = entity.getBody();
MediaType contentType = entity.getHeaders().getContentType();
HttpStatus statusCode = entity.getStatusCode();Can also be used in Spring MVC, as the return value from a @Controller method:
@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);
}Or, by using a builder accessible via static methods:
@RequestMapping("/handle")
public ResponseEntity<String> handle() {
URI location = ...;
return ResponseEntity.created(location).header("MyResponseHeader", "MyValue").body("Hello World");
}
2.返回顶部 |
3.返回顶部 |
4.返回顶部 |
//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
// package org.springframework.http; import java.net.URI;
import java.time.Instant;
import java.time.ZonedDateTime;
import java.util.Arrays;
import java.util.LinkedHashSet;
import java.util.Optional;
import java.util.function.Function;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.MultiValueMap;
import org.springframework.util.ObjectUtils; public class ResponseEntity<T> extends HttpEntity<T> {
private final Object status; public ResponseEntity(HttpStatus status) {
this((Object)null, (MultiValueMap)null, (HttpStatus)status);
} public ResponseEntity(@Nullable T body, HttpStatus status) {
this(body, (MultiValueMap)null, (HttpStatus)status);
} public ResponseEntity(MultiValueMap<String, String> headers, HttpStatus status) {
this((Object)null, headers, (HttpStatus)status);
} public ResponseEntity(@Nullable T body, @Nullable MultiValueMap<String, String> headers, HttpStatus status) {
super(body, headers);
Assert.notNull(status, "HttpStatus must not be null");
this.status = status;
} private ResponseEntity(@Nullable T body, @Nullable MultiValueMap<String, String> headers, Object status) {
super(body, headers);
Assert.notNull(status, "HttpStatus must not be null");
this.status = status;
} public HttpStatus getStatusCode() {
return this.status instanceof HttpStatus ? (HttpStatus)this.status : HttpStatus.valueOf((Integer)this.status);
} public int getStatusCodeValue() {
return this.status instanceof HttpStatus ? ((HttpStatus)this.status).value() : (Integer)this.status;
} public boolean equals(@Nullable Object other) {
if (this == other) {
return true;
} else if (!super.equals(other)) {
return false;
} else {
ResponseEntity<?> otherEntity = (ResponseEntity)other;
return ObjectUtils.nullSafeEquals(this.status, otherEntity.status);
}
} public int hashCode() {
return super.hashCode() * 29 + ObjectUtils.nullSafeHashCode(this.status);
} public String toString() {
StringBuilder builder = new StringBuilder("<");
builder.append(this.status.toString());
if (this.status instanceof HttpStatus) {
builder.append(' ');
builder.append(((HttpStatus)this.status).getReasonPhrase());
} builder.append(',');
T body = this.getBody();
HttpHeaders headers = this.getHeaders();
if (body != null) {
builder.append(body);
builder.append(',');
} builder.append(headers);
builder.append('>');
return builder.toString();
} public static ResponseEntity.BodyBuilder status(HttpStatus status) {
Assert.notNull(status, "HttpStatus must not be null");
return new ResponseEntity.DefaultBuilder(status);
} public static ResponseEntity.BodyBuilder status(int status) {
return new ResponseEntity.DefaultBuilder(status);
} public static <T> ResponseEntity<T> of(Optional<T> body) {
Assert.notNull(body, "Body must not be null");
return (ResponseEntity)body.map(ResponseEntity::ok).orElse(notFound().build());
} public static ResponseEntity.BodyBuilder ok() {
return status(HttpStatus.OK);
} public static <T> ResponseEntity<T> ok(T body) {
ResponseEntity.BodyBuilder builder = ok();
return builder.body(body);
} public static ResponseEntity.BodyBuilder created(URI location) {
ResponseEntity.BodyBuilder builder = status(HttpStatus.CREATED);
return (ResponseEntity.BodyBuilder)builder.location(location);
} public static ResponseEntity.BodyBuilder accepted() {
return status(HttpStatus.ACCEPTED);
} public static ResponseEntity.HeadersBuilder<?> noContent() {
return status(HttpStatus.NO_CONTENT);
} public static ResponseEntity.BodyBuilder badRequest() {
return status(HttpStatus.BAD_REQUEST);
} public static ResponseEntity.HeadersBuilder<?> notFound() {
return status(HttpStatus.NOT_FOUND);
} public static ResponseEntity.BodyBuilder unprocessableEntity() {
return status(HttpStatus.UNPROCESSABLE_ENTITY);
} private static class DefaultBuilder implements ResponseEntity.BodyBuilder {
private final Object statusCode;
private final HttpHeaders headers = new HttpHeaders(); public DefaultBuilder(Object statusCode) {
this.statusCode = statusCode;
} public ResponseEntity.BodyBuilder header(String headerName, String... headerValues) {
String[] var3 = headerValues;
int var4 = headerValues.length; for(int var5 = 0; var5 < var4; ++var5) {
String headerValue = var3[var5];
this.headers.add(headerName, headerValue);
} return this;
} public ResponseEntity.BodyBuilder headers(@Nullable HttpHeaders headers) {
if (headers != null) {
this.headers.putAll(headers);
} return this;
} public ResponseEntity.BodyBuilder allow(HttpMethod... allowedMethods) {
this.headers.setAllow(new LinkedHashSet(Arrays.asList(allowedMethods)));
return this;
} public ResponseEntity.BodyBuilder contentLength(long contentLength) {
this.headers.setContentLength(contentLength);
return this;
} public ResponseEntity.BodyBuilder contentType(MediaType contentType) {
this.headers.setContentType(contentType);
return this;
} public ResponseEntity.BodyBuilder eTag(String etag) {
if (!etag.startsWith("\"") && !etag.startsWith("W/\"")) {
etag = "\"" + etag;
} if (!etag.endsWith("\"")) {
etag = etag + "\"";
} this.headers.setETag(etag);
return this;
} public ResponseEntity.BodyBuilder lastModified(ZonedDateTime date) {
this.headers.setLastModified(date);
return this;
} public ResponseEntity.BodyBuilder lastModified(Instant date) {
this.headers.setLastModified(date);
return this;
} public ResponseEntity.BodyBuilder lastModified(long date) {
this.headers.setLastModified(date);
return this;
} public ResponseEntity.BodyBuilder location(URI location) {
this.headers.setLocation(location);
return this;
} public ResponseEntity.BodyBuilder cacheControl(CacheControl cacheControl) {
this.headers.setCacheControl(cacheControl);
return this;
} public ResponseEntity.BodyBuilder varyBy(String... requestHeaders) {
this.headers.setVary(Arrays.asList(requestHeaders));
return this;
} public <T> ResponseEntity<T> build() {
return this.body((Object)null);
} public <T> ResponseEntity<T> body(@Nullable T body) {
return new ResponseEntity(body, this.headers, this.statusCode);
}
} public interface BodyBuilder extends ResponseEntity.HeadersBuilder<ResponseEntity.BodyBuilder> {
ResponseEntity.BodyBuilder contentLength(long var1); ResponseEntity.BodyBuilder contentType(MediaType var1); <T> ResponseEntity<T> body(@Nullable T var1);
} public interface HeadersBuilder<B extends ResponseEntity.HeadersBuilder<B>> {
B header(String var1, String... var2); B headers(@Nullable HttpHeaders var1); B allow(HttpMethod... var1); B eTag(String var1); B lastModified(ZonedDateTime var1); B lastModified(Instant var1); B lastModified(long var1); B location(URI var1); B cacheControl(CacheControl var1); B varyBy(String... var1); <T> ResponseEntity<T> build();
}
}
5.返回顶部 |
6.返回顶部 |
作者:ylbtech 出处:http://ylbtech.cnblogs.com/ 本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。 |
Java-Class-C:org.springframework.http.ResponseEntity的更多相关文章
- Spring整合Mybatis报 java.lang.ClassNotFoundException:org.springframework.core.metrics.ApplicationStartup,即:spring的版本过高,采用RELEASE稳定版
1.遇到的问题: 今天在弄spring整合mybatis的时候遇到一个小问题,如图所示: 简单来说:就是我的spring的xml文件没找到,我就奇了怪了,我所有的配置都没问题啊! 我pom.xml配置 ...
- SSM报错:No converter found for return value of type: class java.util.ArrayList at org.springframework.web.servlet.mvc.method.annotation.AbstractMessageConverterMethodProcessor.writeWithMessageConverter
我使用的是SSM框架,是在编写测试RESTFUL接口的时候出现, @RequestMapping(value = "/selectAll", method = RequestMet ...
- Spring 整合 Flex (BlazeDS)无法从as对象 到 Java对象转换的异常:org.springframework.beans.ConversionNotSupportedException: Failed to convert property value of type 'java.util.Date' to required type 'java.sql.Timestamp' for property 'wfsj'; nested exception is java.lang.Ill
异常信息如下: org.springframework.beans.ConversionNotSupportedException: Failed to convert property value ...
- 【spring mvc】后台spring mvc接收List参数报错如下:org.springframework.beans.BeanInstantiationException: Failed to instantiate [java.util.List]: Specified class is an interface
后台spring mvc接收List参数报错如下:org.springframework.beans.BeanInstantiationException: Failed to instantiate ...
- Java-Class-C:org.springframework.web.client.RestTemplate
ylbtech-Java-Class-C:org.springframework.web.client.RestTemplate 1.返回顶部 1. org.springframework.web.c ...
- Java Web系列:Spring Boot 基础
Spring Boot 项目(参考1) 提供了一个类似ASP.NET MVC的默认模板一样的标准样板,直接集成了一系列的组件并使用了默认的配置.使用Spring Boot 不会降低学习成本,甚至增加了 ...
- Java Web系列:Spring Boot 基础 (转)
Spring Boot 项目(参考1) 提供了一个类似ASP.NET MVC的默认模板一样的标准样板,直接集成了一系列的组件并使用了默认的配置.使用Spring Boot 不会降低学习成本,甚至增加了 ...
- Spring MVC报异常:org.springframework.web.util.NestedServletException: Request processing failed
在使用SpringMVC绑定基本类型(如String,Integer等)参数时,应通过@RequestParam注解指定具体的参数名称,否则,当源代码在非debug模式下编译后,运行时会引发Handl ...
- 项目maven update 后启动项目出现导常:org.springframework.web.context.ContextLoaderListener
导常:org.springframework.web.context.ContextLoaderListener 1. 右键单击工程项目 ->点击 properties2. 选择 Deploym ...
随机推荐
- 深入理解MAGENTO – 第九章 – 数据集合瓦瑞恩
本来,作为一个PHP程序员,如果你想攒一组变量的相关你有一个选择,古老的 阵列 . 尽管共享一个地址的名称与C存储器的阵列,一个PHP数组是一种通用的字典可变数组索引像数值对象结合行为的影响. 在其他 ...
- PHP FILTER_SANITIZE_MAGIC_QUOTES 过滤器
定义和用法 FILTER_SANITIZE_MAGIC_QUOTES 过滤器对字符串执行 addslashes() 函数. 该过滤器在预定义的字符串前面设置反斜杠. 预定义字符是: 单引号(') 双引 ...
- BZOJ 4319: cerc2008 Suffix reconstruction(后缀数组)
题面 Description 话说练习后缀数组时,小C 刷遍 poj 后缀数组题, 各类字符串题闻之丧胆.就在准备对敌方武将发出连环杀时,对方一记无中生有,又一招顺 手牵羊,小C 程序中的原字符数组就 ...
- mysql注入篇
博客这个东西真的很考验耐心,每写一篇笔记,都是在艰难的决定中施行的,毕竟谁都有懒惰的一面,就像这个,mysql注入篇,拖拖拖一直拖到现在才开始总结,因为这个实在是太多太杂了,细细的总结一篇太烧脑. 由 ...
- Android逆向之smali语法宝典
0x01.前言 Android采用的是java语言进行开发,但是Android系统有自己的虚拟机Dalvik,代码编译最终不是采用的java的class,而是使用的smali.我们反编译得到的代码,j ...
- 在Windows上安装部署Cuckoo
1. Cuckoo使用的第三方工具及库 Yara:http://plusvic.github.io/yara/ Pydeep:https://github.com/kbandla/pydeep Yar ...
- 机器学习技法笔记:02 Dual Support Vector Machine、KKT
原文地址:https://www.jianshu.com/p/58259cdde0e1 Roadmap Motivation of Dual SVM Lagrange Dual SVM Solving ...
- 并发基础篇(六):线程Thread类的start()方法和run()方法【转载】
[转载] 一.初识java的线程是通过java.lang.Thread类来实现的.VM启动时会有一个由主方法所定义的线程.可以通过创建Thread的实例来创建新的线程.每个线程都是通过某个特定Thre ...
- scala 实现算法
快速排序 def sort(xs: Array[Int]): Array[Int] = if (xs.length <= 1) xs else { val pivot = xs(xs.lengt ...
- <python基础>python继承机制
子类在调用某个方法或变量的时候,首先在自己内部查找,如果没有找到,则开始根据继承机制在父类里查找. 根据父类定义中的顺序,以深度优先的方式逐一查找父类! class D: def show(self) ...