<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                # Spring REST – HTTP OPTIONS 請求處理器示例 > 原文: [https://howtodoinjava.com/spring-restful/http-options-request-handler/](https://howtodoinjava.com/spring-restful/http-options-request-handler/) 通過為`RequestMethod.OPTIONS`添加特定的處理器方法,學習在 [Spring webmvc](https://howtodoinjava.com/spring-mvc-tutorial/) 應用程序中處理特定于 REST 資源的 HTTP **選項**請求。 ## 1\. HTTP OPTIONS 方法 [HTTP OPTIONS](https://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html#sec9.2) 方法用于描述目標資源的**通信選項**。 此方法允許客戶端確定與資源相關聯的選項和/或要求,或者服務器的功能,而無需暗示資源操作或啟動資源檢索。 * 如果 Request-URI 是星號(`*`),則 OPTIONS 請求通常適用于服務器而不是特定資源。 * 如果 Request-URI 不是星號,則 OPTIONS 請求僅適用于與該資源進行通信時可用的選項。 * 此方法的響應是**不可緩存**。 ## 2\. 將選項處理器方法添加到 REST 控制器 下一步是添加處理器方法以處理 OPTIONS 請求。 `EmployeeRESTController.java` ```java @RestController @RequestMapping(value = "/employee-management", produces = { MediaType.APPLICATION_JSON_VALUE }) public class EmployeeRESTController { @RequestMapping(value="/employees", method = RequestMethod.OPTIONS) ResponseEntity<?> collectionOptions() { return ResponseEntity .ok() .allow(HttpMethod.GET, HttpMethod.POST, HttpMethod.OPTIONS) .build(); } @RequestMapping(value="/employees/{id}", method = RequestMethod.OPTIONS) ResponseEntity<?> singularOptions() { return ResponseEntity .ok() .allow(HttpMethod.GET, HttpMethod.DELETE, HttpMethod.PUT, HttpMethod.OPTIONS) .build(); } //Other APIs } ``` ## 3\. 演示 要測試 OPTIONS 請求是否被正確處理,請在任何 REST 客戶端插件或 SoapUI 中進行測試。 > 點擊 URL:HTTP 選項`http://localhost:8080/api/rest/employee-management/employees/1` 在 [cURL](https://howtodoinjava.com/for-fun-only/curl-in-windows/) 中,我們可以通過點擊以下 URL 進行測試。 `Option 驗證響應 - 1` ```java curl -i -X OPTIONS http://localhost:8080/SpringRestExample/api/rest/employee-management/employees/ Response: #status# HTTP/1.1 200 OK Server Apache-Coyote/1.1 Content-Length 0 Date Thu, 02 May 2019 10:41:02 GMT Allow GET,POST,OPTIONS ``` `Option 驗證響應 - 2` ```java curl -i -X OPTIONS http://localhost:8080/SpringRestExample/api/rest/employee-management/employees/1 Response: #status# HTTP/1.1 200 OK Server Apache-Coyote/1.1 Content-Length 0 Date Thu, 02 May 2019 10:43:15 GMT Allow GET,DELETE,PUT,OPTIONS ``` 學習愉快!
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看