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

                ??一站式輕松地調用各大LLM模型接口,支持GPT4、智譜、豆包、星火、月之暗面及文生圖、文生視頻 廣告
                # 通用注解修飾方法 修飾方法的作用是對路由進行一些預處理處理再返回給方法。 >[info] 以下修飾方法不管是GET或者POST,均可使用 | 注解名稱 | 注解作用 | | --- | --- | | @PathVariable | 獲取自定義路由 `占位符` 的參數,并導入到方法中(支持多個),如果增加參數 `required=true`,則不到該參數會拋出一個http 400的 異常 | | @RequestParam | 獲取路由某個參數也就是`?`后面的,并導入到方法中(支持多個) | | @ResponseBody | 對回的數據增加 Content-type :json,否則默認為html | ~~~ /** * post 表單 請求 * @PostMapping("test4/{name}") * @PathVariable("name", required=true) * @param $name * @return string */ public function test4($name){ var_dump($name); return "test444"; } ~~~ 訪問 [http://serverName:8080/test/hello](http://127.0.0.1:8080/test/hello) 。那么`hello` 就會傳遞到name綁定的變量中去,最終test4(`$name`) 被傳遞了 hello。如果沒有傳遞{name},則會拋出 http 400 的異常。 ~~~ /** * get請求 * @GetMapping("test/{name2}/{name3}") * @PathVariable("name2") * @PathVariable("name3") * @RequestParam("id") * @param $name2 * @param $name2 * @param $id * @return string */ public function test($name2, $name3, $id) { var_dump($name2, $name3, $id); return "test222"; } ~~~ 訪問 http://127.0.0.1:8080/test/hello/world?id=99 。那么`hello`會傳遞到 `$name2`變量,`world`會傳遞到`$name3`的變量中,`99`會傳遞到`$id`中。 >[info] PathVariable,RequestParam 還支持 required 參數,如果設置為true,那么當該參數不存在時會拋出異常 # POST修飾方法 POST修飾方法幫助我們在接收到參數的時候進行一些預處理。 > 以下修飾方法僅限在POST,PUT下使用。 | 注解名稱 | 注解作用 | | --- | --- | | @RequestBody | 從原始請求raw中解析json字符串,并轉為數組。如果解析失敗拋出異常。 | | @RequestRawJson | 同上 | | @RequestRaw | 直接獲取post的未編碼raw數據 | | @RequestRawXml | 從從原始請求raw中解析xml字符串,并轉為數組。如果解析失敗拋出異常。 | | @ModelAttribute | 獲獲取POST數據,導入給model對象,或傳給一個數組。 | | @RequestFormData | 獲獲取POST數據的一個參數,傳給一個參數。 | > POST修飾注釋,只能在申明了 PostMapping()注解的方法上使用 > \* ## @RequestBody `POST`一個`raw`的 json 數據。`$body`收到的就為轉化成數組的表單數據,如果解析失敗拋出異常。 ~~~ /** * @PostMapping() * @RequestBody("body") */ public function test8($body){ print_r($body); return 'test8'; } ~~~ ## **@RequestRaw** `POST`一個 raw數據,`$raw`收到的就為原始表單數據。 ~~~ /** * @PostMapping("test6/{name}") * @RequestRaw("raw") * @param $raw * @return string */ public function test6($raw){ var_dump($name, $raw); return "test6"; } ~~~ ## **@RequestRawXml** `POST`一個xml raw,那么`$test`收到的就為轉換成數組后的表單數據。 ~~~ /** * @PostMapping() * @RequestRawXml("test") * @param $test * @return string */ public function test7($test){ var_dump($test); return 'test7'; } ~~~ ## **@ModelAttribute** >[danger] 如果使用 RequestBody,RequestRaw\* 相關方法,則該注解不可用。 `POST`一個表單數據(form-data或www-form-urnecoded),testForm 類型的 $test 變量會被填充數據。 如果傳遞page=1,對象的屬性就會被自動覆蓋。如果不給變量傳遞類型,則該變量拿到post所有數據。 ~~~ /** * post 表單 請求 * @PostMapping("test3/{name}") * @PathVariable("name") * @ModelAttribute("test") * @param $name * @param $test * @return string * 實際上是 獲取整個post表單的數據 到聲明的變量里 */ public function test3($name, testForm $test) { print_r($this->request->post()); var_dump($name, $test); return "test444"; } class testForm { public $page = 1; public $test = 0; } ~~~ ## RequestFormData 將表單的一個參數填充到類方法的變量中。 POST hhh=123,則 `$hhh` 為 123 ~~~ /** * post 表單 請求 * @PostMapping("test4/{name}") * @PathVariable("name") * @RequestFormData("hhh") * @param $name * @param $test * @return string * 知己上只能獲取聲明的字段 */ public function test4($name, $hhh){ var_dump($name, $hhh); return "test444"; } ~~~
                  <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>

                              哎呀哎呀视频在线观看