java定义接口返回状态_spring boot接口 自定义返回接口状态码及返回信息

/** Copyright 2002-2017 the original author or authors.

*

* Licensed under the Apache License, Version 2.0 (the "License");

* you may not use this file except in compliance with the License.

* You may obtain a copy of the License at

*

*http://www.apache.org/licenses/LICENSE-2.0*

* Unless required by applicable law or agreed to in writing, software

* distributed under the License is distributed on an "AS IS" BASIS,

* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

* See the License for the specific language governing permissions and

* limitations under the License.*/

packageorg.springframework.http;/*** Enumeration of HTTP status codes.

*

*

The HTTP status code series can be retrieved via {@link#series()}.

*

*@authorArjen Poutsma

*@authorSebastien Deleuze

*@authorBrian Clozel

*@since3.0

*@seeHttpStatus.Series

*@seeHTTP Status Code Registry

*@seeList of HTTP status codes - Wikipedia*/

public enumHttpStatus {//1xx Informational

/*** {@code100 Continue}.

*@seeHTTP/1.1: Semantics and Content, section 6.2.1*/CONTINUE(100, "Continue"),/*** {@code101 Switching Protocols}.

*@seeHTTP/1.1: Semantics and Content, section 6.2.2*/SWITCHING_PROTOCOLS(101, "Switching Protocols"),/*** {@code102 Processing}.

*@seeWebDAV*/PROCESSING(102, "Processing"),/*** {@code103 Checkpoint}.

*@seeA proposal for supporting

* resumable POST/PUT HTTP requests in HTTP/1.0*/CHECKPOINT(103, "Checkpoint"),//2xx Success

/*** {@code200 OK}.

*@seeHTTP/1.1: Semantics and Content, section 6.3.1*/OK(200, "OK"),/*** {@code201 Created}.

*@seeHTTP/1.1: Semantics and Content, section 6.3.2*/CREATED(201, "Created"),/*** {@code202 Accepted}.

*@seeHTTP/1.1: Semantics and Content, section 6.3.3*/ACCEPTED(202, "Accepted"),/*** {@code203 Non-Authoritative Information}.

*@seeHTTP/1.1: Semantics and Content, section 6.3.4*/NON_AUTHORITATIVE_INFORMATION(203, "Non-Authoritative Information"),/*** {@code204 No Content}.

*@seeHTTP/1.1: Semantics and Content, section 6.3.5*/NO_CONTENT(204, "No Content"),/*** {@code205 Reset Content}.

*@seeHTTP/1.1: Semantics and Content, section 6.3.6*/RESET_CONTENT(205, "Reset Content"),/*** {@code206 Partial Content}.

*@seeHTTP/1.1: Range Requests, section 4.1*/PARTIAL_CONTENT(206, "Partial Content"),/*** {@code207 Multi-Status}.

*@seeWebDAV*/MULTI_STATUS(207, "Multi-Status"),/*** {@code208 Already Reported}.

*@seeWebDAV Binding Extensions*/ALREADY_REPORTED(208, "Already Reported"),/*** {@code226 IM Used}.

*@seeDelta encoding in HTTP*/IM_USED(226, "IM Used"),//3xx Redirection

/*** {@code300 Multiple Choices}.

*@seeHTTP/1.1: Semantics and Content, section 6.4.1*/MULTIPLE_CHOICES(300, "Multiple Choices"),/*** {@code301 Moved Permanently}.

*@seeHTTP/1.1: Semantics and Content, section 6.4.2*/MOVED_PERMANENTLY(301, "Moved Permanently"),/*** {@code302 Found}.

*@seeHTTP/1.1: Semantics and Content, section 6.4.3*/FOUND(302, "Found"),/*** {@code302 Moved Temporarily}.

*@seeHTTP/1.0, section 9.3

*@deprecatedin favor of {@link#FOUND} which will be returned from {@codeHttpStatus.valueOf(302)}*/@Deprecated

MOVED_TEMPORARILY(302, "Moved Temporarily"),/*** {@code303 See Other}.

*@seeHTTP/1.1: Semantics and Content, section 6.4.4*/SEE_OTHER(303, "See Other"),/*** {@code304 Not Modified}.

*@seeHTTP/1.1: Conditional Requests, section 4.1*/NOT_MODIFIED(304, "Not Modified"),/*** {@code305 Use Proxy}.

*@seeHTTP/1.1: Semantics and Content, section 6.4.5

*@deprecateddue to security concerns regarding in-band configuration of a proxy*/@Deprecated

USE_PROXY(305, "Use Proxy"),/*** {@code307 Temporary Redirect}.

*@seeHTTP/1.1: Semantics and Content, section 6.4.7*/TEMPORARY_REDIRECT(307, "Temporary Redirect"),/*** {@code308 Permanent Redirect}.

*@seeRFC 7238*/PERMANENT_REDIRECT(308, "Permanent Redirect"),//--- 4xx Client Error ---

/*** {@code400 Bad Request}.

*@seeHTTP/1.1: Semantics and Content, section 6.5.1*/BAD_REQUEST(400, "Bad Request"),/*** {@code401 Unauthorized}.

*@seeHTTP/1.1: Authentication, section 3.1*/UNAUTHORIZED(401, "Unauthorized"),/*** {@code402 Payment Required}.

*@seeHTTP/1.1: Semantics and Content, section 6.5.2*/PAYMENT_REQUIRED(402, "Payment Required"),/*** {@code403 Forbidden}.

*@seeHTTP/1.1: Semantics and Content, section 6.5.3*/FORBIDDEN(403, "Forbidden"),/*** {@code404 Not Found}.

*@seeHTTP/1.1: Semantics and Content, section 6.5.4*/NOT_FOUND(404, "Not Found"),/*** {@code405 Method Not Allowed}.

*@seeHTTP/1.1: Semantics and Content, section 6.5.5*/METHOD_NOT_ALLOWED(405, "Method Not Allowed"),/*** {@code406 Not Acceptable}.

*@seeHTTP/1.1: Semantics and Content, section 6.5.6*/NOT_ACCEPTABLE(406, "Not Acceptable"),/*** {@code407 Proxy Authentication Required}.

*@seeHTTP/1.1: Authentication, section 3.2*/PROXY_AUTHENTICATION_REQUIRED(407, "Proxy Authentication Required"),/*** {@code408 Request Timeout}.

*@seeHTTP/1.1: Semantics and Content, section 6.5.7*/REQUEST_TIMEOUT(408, "Request Timeout"),/*** {@code409 Conflict}.

*@seeHTTP/1.1: Semantics and Content, section 6.5.8*/CONFLICT(409, "Conflict"),/*** {@code410 Gone}.

*@seeHTTP/1.1: Semantics and Content, section 6.5.9*/GONE(410, "Gone"),/*** {@code411 Length Required}.

*@seeHTTP/1.1: Semantics and Content, section 6.5.10*/LENGTH_REQUIRED(411, "Length Required"),/*** {@code412 Precondition failed}.

*@seeHTTP/1.1: Conditional Requests, section 4.2*/PRECONDITION_FAILED(412, "Precondition Failed"),/*** {@code413 Payload Too Large}.

*@since4.1

*@seeHTTP/1.1: Semantics and Content, section 6.5.11*/PAYLOAD_TOO_LARGE(413, "Payload Too Large"),/*** {@code413 Request Entity Too Large}.

*@seeHTTP/1.1, section 10.4.14

*@deprecatedin favor of {@link#PAYLOAD_TOO_LARGE} which will be returned from {@codeHttpStatus.valueOf(413)}*/@Deprecated

REQUEST_ENTITY_TOO_LARGE(413, "Request Entity Too Large"),/*** {@code414 URI Too Long}.

*@since4.1

*@seeHTTP/1.1: Semantics and Content, section 6.5.12*/URI_TOO_LONG(414, "URI Too Long"),/*** {@code414 Request-URI Too Long}.

*@seeHTTP/1.1, section 10.4.15

*@deprecatedin favor of {@link#URI_TOO_LONG} which will be returned from {@codeHttpStatus.valueOf(414)}*/@Deprecated

REQUEST_URI_TOO_LONG(414, "Request-URI Too Long"),/*** {@code415 Unsupported Media Type}.

*@seeHTTP/1.1: Semantics and Content, section 6.5.13*/UNSUPPORTED_MEDIA_TYPE(415, "Unsupported Media Type"),/*** {@code416 Requested Range Not Satisfiable}.

*@seeHTTP/1.1: Range Requests, section 4.4*/REQUESTED_RANGE_NOT_SATISFIABLE(416, "Requested range not satisfiable"),/*** {@code417 Expectation Failed}.

*@seeHTTP/1.1: Semantics and Content, section 6.5.14*/EXPECTATION_FAILED(417, "Expectation Failed"),/*** {@code418 I'm a teapot}.

*@seeHTCPCP/1.0*/I_AM_A_TEAPOT(418, "I'm a teapot"),/***@deprecatedSee WebDAV Draft Changes*/@Deprecated

INSUFFICIENT_SPACE_ON_RESOURCE(419, "Insufficient Space On Resource"),/***@deprecatedSee WebDAV Draft Changes*/@Deprecated

METHOD_FAILURE(420, "Method Failure"),/***@deprecatedSee WebDAV Draft Changes*/@Deprecated

DESTINATION_LOCKED(421, "Destination Locked"),/*** {@code422 Unprocessable Entity}.

*@seeWebDAV*/UNPROCESSABLE_ENTITY(422, "Unprocessable Entity"),/*** {@code423 Locked}.

*@seeWebDAV*/LOCKED(423, "Locked"),/*** {@code424 Failed Dependency}.

*@seeWebDAV*/FAILED_DEPENDENCY(424, "Failed Dependency"),/*** {@code426 Upgrade Required}.

*@seeUpgrading to TLS Within HTTP/1.1*/UPGRADE_REQUIRED(426, "Upgrade Required"),/*** {@code428 Precondition Required}.

*@seeAdditional HTTP Status Codes*/PRECONDITION_REQUIRED(428, "Precondition Required"),/*** {@code429 Too Many Requests}.

*@seeAdditional HTTP Status Codes*/TOO_MANY_REQUESTS(429, "Too Many Requests"),/*** {@code431 Request Header Fields Too Large}.

*@seeAdditional HTTP Status Codes*/REQUEST_HEADER_FIELDS_TOO_LARGE(431, "Request Header Fields Too Large"),/*** {@code451 Unavailable For Legal Reasons}.

*@see

* An HTTP Status Code to Report Legal Obstacles

*@since4.3*/UNAVAILABLE_FOR_LEGAL_REASONS(451, "Unavailable For Legal Reasons"),//--- 5xx Server Error ---

/*** {@code500 Internal Server Error}.

*@seeHTTP/1.1: Semantics and Content, section 6.6.1*/INTERNAL_SERVER_ERROR(500, "Internal Server Error"),/*** {@code501 Not Implemented}.

*@seeHTTP/1.1: Semantics and Content, section 6.6.2*/NOT_IMPLEMENTED(501, "Not Implemented"),/*** {@code502 Bad Gateway}.

*@seeHTTP/1.1: Semantics and Content, section 6.6.3*/BAD_GATEWAY(502, "Bad Gateway"),/*** {@code503 Service Unavailable}.

*@seeHTTP/1.1: Semantics and Content, section 6.6.4*/SERVICE_UNAVAILABLE(503, "Service Unavailable"),/*** {@code504 Gateway Timeout}.

*@seeHTTP/1.1: Semantics and Content, section 6.6.5*/GATEWAY_TIMEOUT(504, "Gateway Timeout"),/*** {@code505 HTTP Version Not Supported}.

*@seeHTTP/1.1: Semantics and Content, section 6.6.6*/HTTP_VERSION_NOT_SUPPORTED(505, "HTTP Version not supported"),/*** {@code506 Variant Also Negotiates}

*@seeTransparent Content Negotiation*/VARIANT_ALSO_NEGOTIATES(506, "Variant Also Negotiates"),/*** {@code507 Insufficient Storage}

*@seeWebDAV*/INSUFFICIENT_STORAGE(507, "Insufficient Storage"),/*** {@code508 Loop Detected}

*@seeWebDAV Binding Extensions*/LOOP_DETECTED(508, "Loop Detected"),/*** {@code509 Bandwidth Limit Exceeded}*/BANDWIDTH_LIMIT_EXCEEDED(509, "Bandwidth Limit Exceeded"),/*** {@code510 Not Extended}

*@seeHTTP Extension Framework*/NOT_EXTENDED(510, "Not Extended"),/*** {@code511 Network Authentication Required}.

*@seeAdditional HTTP Status Codes*/NETWORK_AUTHENTICATION_REQUIRED(511, "Network Authentication Required");private final intvalue;private finalString reasonPhrase;

HttpStatus(intvalue, String reasonPhrase) {this.value =value;this.reasonPhrase =reasonPhrase;

}/*** Return the integer value of this status code.*/

public intvalue() {return this.value;

}/*** Return the reason phrase of this status code.*/

publicString getReasonPhrase() {return this.reasonPhrase;

}/*** Whether this status code is in the HTTP series

* {@linkorg.springframework.http.HttpStatus.Series#INFORMATIONAL}.

* This is a shortcut for checking the value of {@link#series()}.*/

public booleanis1xxInformational() {returnSeries.INFORMATIONAL.equals(series());

}/*** Whether this status code is in the HTTP series

* {@linkorg.springframework.http.HttpStatus.Series#SUCCESSFUL}.

* This is a shortcut for checking the value of {@link#series()}.*/

public booleanis2xxSuccessful() {returnSeries.SUCCESSFUL.equals(series());

}/*** Whether this status code is in the HTTP series

* {@linkorg.springframework.http.HttpStatus.Series#REDIRECTION}.

* This is a shortcut for checking the value of {@link#series()}.*/

public booleanis3xxRedirection() {returnSeries.REDIRECTION.equals(series());

}/*** Whether this status code is in the HTTP series

* {@linkorg.springframework.http.HttpStatus.Series#CLIENT_ERROR}.

* This is a shortcut for checking the value of {@link#series()}.*/

public booleanis4xxClientError() {returnSeries.CLIENT_ERROR.equals(series());

}/*** Whether this status code is in the HTTP series

* {@linkorg.springframework.http.HttpStatus.Series#SERVER_ERROR}.

* This is a shortcut for checking the value of {@link#series()}.*/

public booleanis5xxServerError() {returnSeries.SERVER_ERROR.equals(series());

}/*** Returns the HTTP status series of this status code.

*@seeHttpStatus.Series*/

publicSeries series() {return Series.valueOf(this);

}/*** Return a string representation of this status code.*/@OverridepublicString toString() {return Integer.toString(this.value);

}/*** Return the enum constant of this type with the specified numeric value.

*@paramstatusCode the numeric value of the enum to be returned

*@returnthe enum constant with the specified numeric value

*@throwsIllegalArgumentException if this enum has no constant for the specified numeric value*/

public static HttpStatus valueOf(intstatusCode) {for(HttpStatus status : values()) {if (status.value ==statusCode) {returnstatus;

}

}throw new IllegalArgumentException("No matching constant for [" + statusCode + "]");

}/*** Enumeration of HTTP status series.

*

Retrievable via {@linkHttpStatus#series()}.*/

public enumSeries {

INFORMATIONAL(1),

SUCCESSFUL(2),

REDIRECTION(3),

CLIENT_ERROR(4),

SERVER_ERROR(5);private final intvalue;

Series(intvalue) {this.value =value;

}/*** Return the integer value of this status series. Ranges from 1 to 5.*/

public intvalue() {return this.value;

}public static Series valueOf(intstatus) {int seriesCode = status / 100;for(Series series : values()) {if (series.value ==seriesCode) {returnseries;

}

}throw new IllegalArgumentException("No matching constant for [" + status + "]");

}public staticSeries valueOf(HttpStatus status) {returnvalueOf(status.value);

}

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
提供的源码资源涵盖了安卓应用、小程序、Python应用和Java应用等多个领域,每个领域都包含了丰富的实例和项目。这些源码都是基于各自平台的最新技术和标准编写,确保了在对应环境下能够无缝运行。同时,源码中配备了详细的注释和文档,帮助用户快速理解代码结构和实现逻辑。 适用人群: 这些源码资源特别适合大学生群体。无论你是计算机相关专业的学生,还是对其他领域编程感兴趣的学生,这些资源都能为你提供宝贵的学习和实践机会。通过学习和运行这些源码,你可以掌握各平台开发的基础知识,提升编程能力和项目实战经验。 使用场景及目标: 在学习阶段,你可以利用这些源码资源进行课程实践、课外项目或毕业设计。通过分析和运行源码,你将深入了解各平台开发的技术细节和最佳实践,逐步培养起自己的项目开发和问题解决能力。此外,在求职或创业过程中,具备跨平台开发能力的大学生将更具竞争力。 其他说明: 为了确保源码资源的可运行性和易用性,特别注意了以下几点:首先,每份源码都提供了详细的运行环境和依赖说明,确保用户能够轻松搭建起开发环境;其次,源码中的注释和文档都非常完善,方便用户快速上手和理解代码;最后,我会定期更新这些源码资源,以适应各平台技术的最新发展和市场需求。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值