ylbtech-Java-Class-E:org.springframework.http.HttpStatus
1.返回顶部
 
2.返回顶部
 
3.返回顶部
 
4.返回顶部
1、
  1. /*
  2. * Copyright 2002-2017 the original author or authors.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16.  
  17. package org.springframework.http;
  18.  
  19. import org.springframework.lang.Nullable;
  20.  
  21. /**
  22. * Enumeration of HTTP status codes.
  23. *
  24. * <p>The HTTP status code series can be retrieved via {@link #series()}.
  25. *
  26. * @author Arjen Poutsma
  27. * @author Sebastien Deleuze
  28. * @author Brian Clozel
  29. * @since 3.0
  30. * @see HttpStatus.Series
  31. * @see <a href="http://www.iana.org/assignments/http-status-codes">HTTP Status Code Registry</a>
  32. * @see <a href="http://en.wikipedia.org/wiki/List_of_HTTP_status_codes">List of HTTP status codes - Wikipedia</a>
  33. */
  34. public enum HttpStatus {
  35.  
  36. // 1xx Informational
  37.  
  38. /**
  39. * {@code 100 Continue}.
  40. * @see <a href="http://tools.ietf.org/html/rfc7231#section-6.2.1">HTTP/1.1: Semantics and Content, section 6.2.1</a>
  41. */
  42. CONTINUE(100, "Continue"),
  43. /**
  44. * {@code 101 Switching Protocols}.
  45. * @see <a href="http://tools.ietf.org/html/rfc7231#section-6.2.2">HTTP/1.1: Semantics and Content, section 6.2.2</a>
  46. */
  47. SWITCHING_PROTOCOLS(101, "Switching Protocols"),
  48. /**
  49. * {@code 102 Processing}.
  50. * @see <a href="http://tools.ietf.org/html/rfc2518#section-10.1">WebDAV</a>
  51. */
  52. PROCESSING(102, "Processing"),
  53. /**
  54. * {@code 103 Checkpoint}.
  55. * @see <a href="http://code.google.com/p/gears/wiki/ResumableHttpRequestsProposal">A proposal for supporting
  56. * resumable POST/PUT HTTP requests in HTTP/1.0</a>
  57. */
  58. CHECKPOINT(103, "Checkpoint"),
  59.  
  60. // 2xx Success
  61.  
  62. /**
  63. * {@code 200 OK}.
  64. * @see <a href="http://tools.ietf.org/html/rfc7231#section-6.3.1">HTTP/1.1: Semantics and Content, section 6.3.1</a>
  65. */
  66. OK(200, "OK"),
  67. /**
  68. * {@code 201 Created}.
  69. * @see <a href="http://tools.ietf.org/html/rfc7231#section-6.3.2">HTTP/1.1: Semantics and Content, section 6.3.2</a>
  70. */
  71. CREATED(201, "Created"),
  72. /**
  73. * {@code 202 Accepted}.
  74. * @see <a href="http://tools.ietf.org/html/rfc7231#section-6.3.3">HTTP/1.1: Semantics and Content, section 6.3.3</a>
  75. */
  76. ACCEPTED(202, "Accepted"),
  77. /**
  78. * {@code 203 Non-Authoritative Information}.
  79. * @see <a href="http://tools.ietf.org/html/rfc7231#section-6.3.4">HTTP/1.1: Semantics and Content, section 6.3.4</a>
  80. */
  81. NON_AUTHORITATIVE_INFORMATION(203, "Non-Authoritative Information"),
  82. /**
  83. * {@code 204 No Content}.
  84. * @see <a href="http://tools.ietf.org/html/rfc7231#section-6.3.5">HTTP/1.1: Semantics and Content, section 6.3.5</a>
  85. */
  86. NO_CONTENT(204, "No Content"),
  87. /**
  88. * {@code 205 Reset Content}.
  89. * @see <a href="http://tools.ietf.org/html/rfc7231#section-6.3.6">HTTP/1.1: Semantics and Content, section 6.3.6</a>
  90. */
  91. RESET_CONTENT(205, "Reset Content"),
  92. /**
  93. * {@code 206 Partial Content}.
  94. * @see <a href="http://tools.ietf.org/html/rfc7233#section-4.1">HTTP/1.1: Range Requests, section 4.1</a>
  95. */
  96. PARTIAL_CONTENT(206, "Partial Content"),
  97. /**
  98. * {@code 207 Multi-Status}.
  99. * @see <a href="http://tools.ietf.org/html/rfc4918#section-13">WebDAV</a>
  100. */
  101. MULTI_STATUS(207, "Multi-Status"),
  102. /**
  103. * {@code 208 Already Reported}.
  104. * @see <a href="http://tools.ietf.org/html/rfc5842#section-7.1">WebDAV Binding Extensions</a>
  105. */
  106. ALREADY_REPORTED(208, "Already Reported"),
  107. /**
  108. * {@code 226 IM Used}.
  109. * @see <a href="http://tools.ietf.org/html/rfc3229#section-10.4.1">Delta encoding in HTTP</a>
  110. */
  111. IM_USED(226, "IM Used"),
  112.  
  113. // 3xx Redirection
  114.  
  115. /**
  116. * {@code 300 Multiple Choices}.
  117. * @see <a href="http://tools.ietf.org/html/rfc7231#section-6.4.1">HTTP/1.1: Semantics and Content, section 6.4.1</a>
  118. */
  119. MULTIPLE_CHOICES(300, "Multiple Choices"),
  120. /**
  121. * {@code 301 Moved Permanently}.
  122. * @see <a href="http://tools.ietf.org/html/rfc7231#section-6.4.2">HTTP/1.1: Semantics and Content, section 6.4.2</a>
  123. */
  124. MOVED_PERMANENTLY(301, "Moved Permanently"),
  125. /**
  126. * {@code 302 Found}.
  127. * @see <a href="http://tools.ietf.org/html/rfc7231#section-6.4.3">HTTP/1.1: Semantics and Content, section 6.4.3</a>
  128. */
  129. FOUND(302, "Found"),
  130. /**
  131. * {@code 302 Moved Temporarily}.
  132. * @see <a href="http://tools.ietf.org/html/rfc1945#section-9.3">HTTP/1.0, section 9.3</a>
  133. * @deprecated in favor of {@link #FOUND} which will be returned from {@code HttpStatus.valueOf(302)}
  134. */
  135. @Deprecated
  136. MOVED_TEMPORARILY(302, "Moved Temporarily"),
  137. /**
  138. * {@code 303 See Other}.
  139. * @see <a href="http://tools.ietf.org/html/rfc7231#section-6.4.4">HTTP/1.1: Semantics and Content, section 6.4.4</a>
  140. */
  141. SEE_OTHER(303, "See Other"),
  142. /**
  143. * {@code 304 Not Modified}.
  144. * @see <a href="http://tools.ietf.org/html/rfc7232#section-4.1">HTTP/1.1: Conditional Requests, section 4.1</a>
  145. */
  146. NOT_MODIFIED(304, "Not Modified"),
  147. /**
  148. * {@code 305 Use Proxy}.
  149. * @see <a href="http://tools.ietf.org/html/rfc7231#section-6.4.5">HTTP/1.1: Semantics and Content, section 6.4.5</a>
  150. * @deprecated due to security concerns regarding in-band configuration of a proxy
  151. */
  152. @Deprecated
  153. USE_PROXY(305, "Use Proxy"),
  154. /**
  155. * {@code 307 Temporary Redirect}.
  156. * @see <a href="http://tools.ietf.org/html/rfc7231#section-6.4.7">HTTP/1.1: Semantics and Content, section 6.4.7</a>
  157. */
  158. TEMPORARY_REDIRECT(307, "Temporary Redirect"),
  159. /**
  160. * {@code 308 Permanent Redirect}.
  161. * @see <a href="http://tools.ietf.org/html/rfc7238">RFC 7238</a>
  162. */
  163. PERMANENT_REDIRECT(308, "Permanent Redirect"),
  164.  
  165. // --- 4xx Client Error ---
  166.  
  167. /**
  168. * {@code 400 Bad Request}.
  169. * @see <a href="http://tools.ietf.org/html/rfc7231#section-6.5.1">HTTP/1.1: Semantics and Content, section 6.5.1</a>
  170. */
  171. BAD_REQUEST(400, "Bad Request"),
  172. /**
  173. * {@code 401 Unauthorized}.
  174. * @see <a href="http://tools.ietf.org/html/rfc7235#section-3.1">HTTP/1.1: Authentication, section 3.1</a>
  175. */
  176. UNAUTHORIZED(401, "Unauthorized"),
  177. /**
  178. * {@code 402 Payment Required}.
  179. * @see <a href="http://tools.ietf.org/html/rfc7231#section-6.5.2">HTTP/1.1: Semantics and Content, section 6.5.2</a>
  180. */
  181. PAYMENT_REQUIRED(402, "Payment Required"),
  182. /**
  183. * {@code 403 Forbidden}.
  184. * @see <a href="http://tools.ietf.org/html/rfc7231#section-6.5.3">HTTP/1.1: Semantics and Content, section 6.5.3</a>
  185. */
  186. FORBIDDEN(403, "Forbidden"),
  187. /**
  188. * {@code 404 Not Found}.
  189. * @see <a href="http://tools.ietf.org/html/rfc7231#section-6.5.4">HTTP/1.1: Semantics and Content, section 6.5.4</a>
  190. */
  191. NOT_FOUND(404, "Not Found"),
  192. /**
  193. * {@code 405 Method Not Allowed}.
  194. * @see <a href="http://tools.ietf.org/html/rfc7231#section-6.5.5">HTTP/1.1: Semantics and Content, section 6.5.5</a>
  195. */
  196. METHOD_NOT_ALLOWED(405, "Method Not Allowed"),
  197. /**
  198. * {@code 406 Not Acceptable}.
  199. * @see <a href="http://tools.ietf.org/html/rfc7231#section-6.5.6">HTTP/1.1: Semantics and Content, section 6.5.6</a>
  200. */
  201. NOT_ACCEPTABLE(406, "Not Acceptable"),
  202. /**
  203. * {@code 407 Proxy Authentication Required}.
  204. * @see <a href="http://tools.ietf.org/html/rfc7235#section-3.2">HTTP/1.1: Authentication, section 3.2</a>
  205. */
  206. PROXY_AUTHENTICATION_REQUIRED(407, "Proxy Authentication Required"),
  207. /**
  208. * {@code 408 Request Timeout}.
  209. * @see <a href="http://tools.ietf.org/html/rfc7231#section-6.5.7">HTTP/1.1: Semantics and Content, section 6.5.7</a>
  210. */
  211. REQUEST_TIMEOUT(408, "Request Timeout"),
  212. /**
  213. * {@code 409 Conflict}.
  214. * @see <a href="http://tools.ietf.org/html/rfc7231#section-6.5.8">HTTP/1.1: Semantics and Content, section 6.5.8</a>
  215. */
  216. CONFLICT(409, "Conflict"),
  217. /**
  218. * {@code 410 Gone}.
  219. * @see <a href="http://tools.ietf.org/html/rfc7231#section-6.5.9">
  220. * HTTP/1.1: Semantics and Content, section 6.5.9</a>
  221. */
  222. GONE(410, "Gone"),
  223. /**
  224. * {@code 411 Length Required}.
  225. * @see <a href="http://tools.ietf.org/html/rfc7231#section-6.5.10">
  226. * HTTP/1.1: Semantics and Content, section 6.5.10</a>
  227. */
  228. LENGTH_REQUIRED(411, "Length Required"),
  229. /**
  230. * {@code 412 Precondition failed}.
  231. * @see <a href="http://tools.ietf.org/html/rfc7232#section-4.2">
  232. * HTTP/1.1: Conditional Requests, section 4.2</a>
  233. */
  234. PRECONDITION_FAILED(412, "Precondition Failed"),
  235. /**
  236. * {@code 413 Payload Too Large}.
  237. * @since 4.1
  238. * @see <a href="http://tools.ietf.org/html/rfc7231#section-6.5.11">
  239. * HTTP/1.1: Semantics and Content, section 6.5.11</a>
  240. */
  241. PAYLOAD_TOO_LARGE(413, "Payload Too Large"),
  242. /**
  243. * {@code 413 Request Entity Too Large}.
  244. * @see <a href="http://tools.ietf.org/html/rfc2616#section-10.4.14">HTTP/1.1, section 10.4.14</a>
  245. * @deprecated in favor of {@link #PAYLOAD_TOO_LARGE} which will be
  246. * returned from {@code HttpStatus.valueOf(413)}
  247. */
  248. @Deprecated
  249. REQUEST_ENTITY_TOO_LARGE(413, "Request Entity Too Large"),
  250. /**
  251. * {@code 414 URI Too Long}.
  252. * @since 4.1
  253. * @see <a href="http://tools.ietf.org/html/rfc7231#section-6.5.12">
  254. * HTTP/1.1: Semantics and Content, section 6.5.12</a>
  255. */
  256. URI_TOO_LONG(414, "URI Too Long"),
  257. /**
  258. * {@code 414 Request-URI Too Long}.
  259. * @see <a href="http://tools.ietf.org/html/rfc2616#section-10.4.15">HTTP/1.1, section 10.4.15</a>
  260. * @deprecated in favor of {@link #URI_TOO_LONG} which will be returned from {@code HttpStatus.valueOf(414)}
  261. */
  262. @Deprecated
  263. REQUEST_URI_TOO_LONG(414, "Request-URI Too Long"),
  264. /**
  265. * {@code 415 Unsupported Media Type}.
  266. * @see <a href="http://tools.ietf.org/html/rfc7231#section-6.5.13">
  267. * HTTP/1.1: Semantics and Content, section 6.5.13</a>
  268. */
  269. UNSUPPORTED_MEDIA_TYPE(415, "Unsupported Media Type"),
  270. /**
  271. * {@code 416 Requested Range Not Satisfiable}.
  272. * @see <a href="http://tools.ietf.org/html/rfc7233#section-4.4">HTTP/1.1: Range Requests, section 4.4</a>
  273. */
  274. REQUESTED_RANGE_NOT_SATISFIABLE(416, "Requested range not satisfiable"),
  275. /**
  276. * {@code 417 Expectation Failed}.
  277. * @see <a href="http://tools.ietf.org/html/rfc7231#section-6.5.14">
  278. * HTTP/1.1: Semantics and Content, section 6.5.14</a>
  279. */
  280. EXPECTATION_FAILED(417, "Expectation Failed"),
  281. /**
  282. * {@code 418 I'm a teapot}.
  283. * @see <a href="http://tools.ietf.org/html/rfc2324#section-2.3.2">HTCPCP/1.0</a>
  284. */
  285. I_AM_A_TEAPOT(418, "I'm a teapot"),
  286. /**
  287. * @deprecated See
  288. * <a href="http://tools.ietf.org/rfcdiff?difftype=--hwdiff&url2=draft-ietf-webdav-protocol-06.txt">
  289. * WebDAV Draft Changes</a>
  290. */
  291. @Deprecated
  292. INSUFFICIENT_SPACE_ON_RESOURCE(419, "Insufficient Space On Resource"),
  293. /**
  294. * @deprecated See
  295. * <a href="http://tools.ietf.org/rfcdiff?difftype=--hwdiff&url2=draft-ietf-webdav-protocol-06.txt">
  296. * WebDAV Draft Changes</a>
  297. */
  298. @Deprecated
  299. METHOD_FAILURE(420, "Method Failure"),
  300. /**
  301. * @deprecated
  302. * See <a href="http://tools.ietf.org/rfcdiff?difftype=--hwdiff&url2=draft-ietf-webdav-protocol-06.txt">
  303. * WebDAV Draft Changes</a>
  304. */
  305. @Deprecated
  306. DESTINATION_LOCKED(421, "Destination Locked"),
  307. /**
  308. * {@code 422 Unprocessable Entity}.
  309. * @see <a href="http://tools.ietf.org/html/rfc4918#section-11.2">WebDAV</a>
  310. */
  311. UNPROCESSABLE_ENTITY(422, "Unprocessable Entity"),
  312. /**
  313. * {@code 423 Locked}.
  314. * @see <a href="http://tools.ietf.org/html/rfc4918#section-11.3">WebDAV</a>
  315. */
  316. LOCKED(423, "Locked"),
  317. /**
  318. * {@code 424 Failed Dependency}.
  319. * @see <a href="http://tools.ietf.org/html/rfc4918#section-11.4">WebDAV</a>
  320. */
  321. FAILED_DEPENDENCY(424, "Failed Dependency"),
  322. /**
  323. * {@code 426 Upgrade Required}.
  324. * @see <a href="http://tools.ietf.org/html/rfc2817#section-6">Upgrading to TLS Within HTTP/1.1</a>
  325. */
  326. UPGRADE_REQUIRED(426, "Upgrade Required"),
  327. /**
  328. * {@code 428 Precondition Required}.
  329. * @see <a href="http://tools.ietf.org/html/rfc6585#section-3">Additional HTTP Status Codes</a>
  330. */
  331. PRECONDITION_REQUIRED(428, "Precondition Required"),
  332. /**
  333. * {@code 429 Too Many Requests}.
  334. * @see <a href="http://tools.ietf.org/html/rfc6585#section-4">Additional HTTP Status Codes</a>
  335. */
  336. TOO_MANY_REQUESTS(429, "Too Many Requests"),
  337. /**
  338. * {@code 431 Request Header Fields Too Large}.
  339. * @see <a href="http://tools.ietf.org/html/rfc6585#section-5">Additional HTTP Status Codes</a>
  340. */
  341. REQUEST_HEADER_FIELDS_TOO_LARGE(431, "Request Header Fields Too Large"),
  342. /**
  343. * {@code 451 Unavailable For Legal Reasons}.
  344. * @see <a href="https://tools.ietf.org/html/draft-ietf-httpbis-legally-restricted-status-04">
  345. * An HTTP Status Code to Report Legal Obstacles</a>
  346. * @since 4.3
  347. */
  348. UNAVAILABLE_FOR_LEGAL_REASONS(451, "Unavailable For Legal Reasons"),
  349.  
  350. // --- 5xx Server Error ---
  351.  
  352. /**
  353. * {@code 500 Internal Server Error}.
  354. * @see <a href="http://tools.ietf.org/html/rfc7231#section-6.6.1">HTTP/1.1: Semantics and Content, section 6.6.1</a>
  355. */
  356. INTERNAL_SERVER_ERROR(500, "Internal Server Error"),
  357. /**
  358. * {@code 501 Not Implemented}.
  359. * @see <a href="http://tools.ietf.org/html/rfc7231#section-6.6.2">HTTP/1.1: Semantics and Content, section 6.6.2</a>
  360. */
  361. NOT_IMPLEMENTED(501, "Not Implemented"),
  362. /**
  363. * {@code 502 Bad Gateway}.
  364. * @see <a href="http://tools.ietf.org/html/rfc7231#section-6.6.3">HTTP/1.1: Semantics and Content, section 6.6.3</a>
  365. */
  366. BAD_GATEWAY(502, "Bad Gateway"),
  367. /**
  368. * {@code 503 Service Unavailable}.
  369. * @see <a href="http://tools.ietf.org/html/rfc7231#section-6.6.4">HTTP/1.1: Semantics and Content, section 6.6.4</a>
  370. */
  371. SERVICE_UNAVAILABLE(503, "Service Unavailable"),
  372. /**
  373. * {@code 504 Gateway Timeout}.
  374. * @see <a href="http://tools.ietf.org/html/rfc7231#section-6.6.5">HTTP/1.1: Semantics and Content, section 6.6.5</a>
  375. */
  376. GATEWAY_TIMEOUT(504, "Gateway Timeout"),
  377. /**
  378. * {@code 505 HTTP Version Not Supported}.
  379. * @see <a href="http://tools.ietf.org/html/rfc7231#section-6.6.6">HTTP/1.1: Semantics and Content, section 6.6.6</a>
  380. */
  381. HTTP_VERSION_NOT_SUPPORTED(505, "HTTP Version not supported"),
  382. /**
  383. * {@code 506 Variant Also Negotiates}
  384. * @see <a href="http://tools.ietf.org/html/rfc2295#section-8.1">Transparent Content Negotiation</a>
  385. */
  386. VARIANT_ALSO_NEGOTIATES(506, "Variant Also Negotiates"),
  387. /**
  388. * {@code 507 Insufficient Storage}
  389. * @see <a href="http://tools.ietf.org/html/rfc4918#section-11.5">WebDAV</a>
  390. */
  391. INSUFFICIENT_STORAGE(507, "Insufficient Storage"),
  392. /**
  393. * {@code 508 Loop Detected}
  394. * @see <a href="http://tools.ietf.org/html/rfc5842#section-7.2">WebDAV Binding Extensions</a>
  395. */
  396. LOOP_DETECTED(508, "Loop Detected"),
  397. /**
  398. * {@code 509 Bandwidth Limit Exceeded}
  399. */
  400. BANDWIDTH_LIMIT_EXCEEDED(509, "Bandwidth Limit Exceeded"),
  401. /**
  402. * {@code 510 Not Extended}
  403. * @see <a href="http://tools.ietf.org/html/rfc2774#section-7">HTTP Extension Framework</a>
  404. */
  405. NOT_EXTENDED(510, "Not Extended"),
  406. /**
  407. * {@code 511 Network Authentication Required}.
  408. * @see <a href="http://tools.ietf.org/html/rfc6585#section-6">Additional HTTP Status Codes</a>
  409. */
  410. NETWORK_AUTHENTICATION_REQUIRED(511, "Network Authentication Required");
  411.  
  412. private final int value;
  413.  
  414. private final String reasonPhrase;
  415.  
  416. HttpStatus(int value, String reasonPhrase) {
  417. this.value = value;
  418. this.reasonPhrase = reasonPhrase;
  419. }
  420.  
  421. /**
  422. * Return the integer value of this status code.
  423. */
  424. public int value() {
  425. return this.value;
  426. }
  427.  
  428. /**
  429. * Return the reason phrase of this status code.
  430. */
  431. public String getReasonPhrase() {
  432. return this.reasonPhrase;
  433. }
  434.  
  435. /**
  436. * Whether this status code is in the HTTP series
  437. * {@link org.springframework.http.HttpStatus.Series#INFORMATIONAL}.
  438. * This is a shortcut for checking the value of {@link #series()}.
  439. */
  440. public boolean is1xxInformational() {
  441. return Series.INFORMATIONAL.equals(series());
  442. }
  443.  
  444. /**
  445. * Whether this status code is in the HTTP series
  446. * {@link org.springframework.http.HttpStatus.Series#SUCCESSFUL}.
  447. * This is a shortcut for checking the value of {@link #series()}.
  448. */
  449. public boolean is2xxSuccessful() {
  450. return Series.SUCCESSFUL.equals(series());
  451. }
  452.  
  453. /**
  454. * Whether this status code is in the HTTP series
  455. * {@link org.springframework.http.HttpStatus.Series#REDIRECTION}.
  456. * This is a shortcut for checking the value of {@link #series()}.
  457. */
  458. public boolean is3xxRedirection() {
  459. return Series.REDIRECTION.equals(series());
  460. }
  461.  
  462. /**
  463. * Whether this status code is in the HTTP series
  464. * {@link org.springframework.http.HttpStatus.Series#CLIENT_ERROR}.
  465. * This is a shortcut for checking the value of {@link #series()}.
  466. */
  467. public boolean is4xxClientError() {
  468. return Series.CLIENT_ERROR.equals(series());
  469. }
  470.  
  471. /**
  472. * Whether this status code is in the HTTP series
  473. * {@link org.springframework.http.HttpStatus.Series#SERVER_ERROR}.
  474. * This is a shortcut for checking the value of {@link #series()}.
  475. */
  476. public boolean is5xxServerError() {
  477. return Series.SERVER_ERROR.equals(series());
  478. }
  479.  
  480. /**
  481. * Whether this status code is in the HTTP series
  482. * {@link org.springframework.http.HttpStatus.Series#CLIENT_ERROR} or
  483. * {@link org.springframework.http.HttpStatus.Series#SERVER_ERROR}.
  484. * This is a shortcut for checking the value of {@link #series()}.
  485. */
  486. public boolean isError() {
  487. return is4xxClientError() || is5xxServerError();
  488. }
  489.  
  490. /**
  491. * Returns the HTTP status series of this status code.
  492. * @see HttpStatus.Series
  493. */
  494. public Series series() {
  495. return Series.valueOf(this);
  496. }
  497.  
  498. /**
  499. * Return a string representation of this status code.
  500. */
  501. @Override
  502. public String toString() {
  503. return Integer.toString(this.value) + " " + name();
  504. }
  505.  
  506. /**
  507. * Return the enum constant of this type with the specified numeric value.
  508. * @param statusCode the numeric value of the enum to be returned
  509. * @return the enum constant with the specified numeric value
  510. * @throws IllegalArgumentException if this enum has no constant for the specified numeric value
  511. */
  512. public static HttpStatus valueOf(int statusCode) {
  513. HttpStatus status = resolve(statusCode);
  514. if (status == null) {
  515. throw new IllegalArgumentException("No matching constant for [" + statusCode + "]");
  516. }
  517. return status;
  518. }
  519.  
  520. /**
  521. * Resolve the given status code to an {@code HttpStatus}, if possible.
  522. * @param statusCode the HTTP status code (potentially non-standard)
  523. * @return the corresponding {@code HttpStatus}, or {@code null} if not found
  524. * @since 5.0
  525. */
  526. @Nullable
  527. public static HttpStatus resolve(int statusCode) {
  528. for (HttpStatus status : values()) {
  529. if (status.value == statusCode) {
  530. return status;
  531. }
  532. }
  533. return null;
  534. }
  535.  
  536. /**
  537. * Enumeration of HTTP status series.
  538. * <p>Retrievable via {@link HttpStatus#series()}.
  539. */
  540. public enum Series {
  541.  
  542. INFORMATIONAL(1),
  543. SUCCESSFUL(2),
  544. REDIRECTION(3),
  545. CLIENT_ERROR(4),
  546. SERVER_ERROR(5);
  547.  
  548. private final int value;
  549.  
  550. Series(int value) {
  551. this.value = value;
  552. }
  553.  
  554. /**
  555. * Return the integer value of this status series. Ranges from 1 to 5.
  556. */
  557. public int value() {
  558. return this.value;
  559. }
  560.  
  561. public static Series valueOf(int status) {
  562. int seriesCode = status / 100;
  563. for (Series series : values()) {
  564. if (series.value == seriesCode) {
  565. return series;
  566. }
  567. }
  568. throw new IllegalArgumentException("No matching constant for [" + status + "]");
  569. }
  570.  
  571. public static Series valueOf(HttpStatus status) {
  572. return valueOf(status.value);
  573. }
  574. }
  575.  
  576. }
2、
5.返回顶部
 
 
6.返回顶部
 
作者:ylbtech
出处:http://ylbtech.cnblogs.com/
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。

Java-Class-E:org.springframework.http.HttpStatus的更多相关文章

  1. Java Code Examples for org.springframework.http.HttpStatus

    http://www.programcreek.com/java-api-examples/index.php?api=org.springframework.http.HttpStatus

  2. Spring整合Mybatis报 java.lang.ClassNotFoundException:org.springframework.core.metrics.ApplicationStartup,即:spring的版本过高,采用RELEASE稳定版

    1.遇到的问题: 今天在弄spring整合mybatis的时候遇到一个小问题,如图所示: 简单来说:就是我的spring的xml文件没找到,我就奇了怪了,我所有的配置都没问题啊! 我pom.xml配置 ...

  3. 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 ...

  4. 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 ...

  5. 【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 ...

  6. Java-Class-C:org.springframework.http.ResponseEntity

    ylbtech-Java-Class-C:org.springframework.http.ResponseEntity 1.返回顶部 1. org.springframework.http Clas ...

  7. Java-Class-C:org.springframework.web.client.RestTemplate

    ylbtech-Java-Class-C:org.springframework.web.client.RestTemplate 1.返回顶部 1. org.springframework.web.c ...

  8. Java Web系列:Spring Boot 基础

    Spring Boot 项目(参考1) 提供了一个类似ASP.NET MVC的默认模板一样的标准样板,直接集成了一系列的组件并使用了默认的配置.使用Spring Boot 不会降低学习成本,甚至增加了 ...

  9. Java Web系列:Spring Boot 基础 (转)

    Spring Boot 项目(参考1) 提供了一个类似ASP.NET MVC的默认模板一样的标准样板,直接集成了一系列的组件并使用了默认的配置.使用Spring Boot 不会降低学习成本,甚至增加了 ...

随机推荐

  1. MySql插入数据成功但是报[Err] 1055

    1.问题: 这两天做insert操作,mysql版本是5.7,insert后虽然成功了,但是会报一个[Err] 1055的错误.具体如下: 2.解决方案: linux环境下,vim到my.cnf,添加 ...

  2. [NOIP模拟测试31]题解

    A.math 考场乱搞拿了95,2333. 考虑裴蜀定理:$ax+by=z$存在整数解,当且仅当$gcd(a,b)|z$. 那么如果某个数能够被拼出来,就必须满足所有$a_i$的$gcd$是它的因子. ...

  3. 析构中delete this

    查看下面代码如何出错 #include <iostream> using namespace std; class A { public: A() { p = this; } ~A() { ...

  4. 01java基础笔记

    计算机组成:运算器,控制器,存储器,输入输出设备(外部设备I/O设备) 机器语言:机器语言,汇编语言,高级语言 人机交互:命令行方式,图形化界面交互方式 JAVA语言平台分为:J2SE,J2ME,J2 ...

  5. win10 打开 sql sever配置管理器

    !找到解决办法啦!WIN10系统 此电脑->右击->管理弹出以上界面啊哈哈哈还有一些解决办法在这个贴吧里...http://tieba.baidu.com/p/3000709047

  6. 深入理解finally关键字,Finally到底是在return前面执行还是在return后面执行

    一:2种finally不会执行的情况 a.在try语句之前就return了 b.try语句中有System.exit();语句 二:finally语句在return执行之后,return返回之前执行 ...

  7. Django框架(二十五)—— Django rest_framework-路由控制与响应器

    路由控制与响应器 一.路由控制 # 1.基本路由: url(r'^publish/$', views.PublishView.as_view()), # 2.半自动路径:views.PublishVi ...

  8. yum update过程中失败后再次执行出现“xxxx is a duplicate with xxxx”问题

    问题现象: 解决办法: 利用yum-uitls中的工具package-cleanup指令,使用方法见下图,具体可通过man package-cleanup查询 列出重复的rpm包        pac ...

  9. Java7任务并行执行神器:Fork&Join框架

    Fork/Join是什么? Fork/Join框架是Java7提供的并行执行任务框架,思想是将大任务分解成小任务,然后小任务又可以继续分解,然后每个小任务分别计算出结果再合并起来,最后将汇总的结果作为 ...

  10. Android apiDemo 学习——对话框AlertDialogSamples

    版权声明:本文为博主原创文章,未经博主同意不得转载. https://blog.csdn.net/zpf8861/article/details/31423049 注意:该代码仅仅适用于当次简单调用对 ...