1、Query String Parameters
發起get請求參數顯示與url上,其參數跟在?後面且以&分割不同的參數
例子(後端springboot restful
風格)
前端:http://xxx/getTest?name=測試&password=測試2
後端:(參數可以使用類接收)
@GetMapping("/getTest")
public String test(String name,String password) {
return "success";
}
2、Form Data
content-type不設的話默認就是application/x-www-form-urlencoded 對於Post body內
將鍵值對的參數用&連接起來,如果有空格,將空格轉換爲+加號;有特殊符號,將特殊符號轉換爲ASCII
HEX值,其實就是以鍵值的方式傳到後端的,那麼後端不要用@RequestBody來接收即不要用一個類來接收,可以多個參數,因爲是鍵值對,所以要鍵值來接收,其中如果有文件之類的就是multipart/form-data
對於Get 因爲瀏覽器是默認的application/x-www-form-urlencoded,所以第一種Query String
Parameters其實就是不設content-type而出來的結果,其參數跟在?後面且以&分割不同的參數
例子(後端springboot restful
風格)
前端:http://xxx/getTest?name=測試&password=測試2
(不顯示在瀏覽器上)。參數以Form Data
鍵值對的形式傳遞
後端:(參數可以使用類接收)
@PostMapping("/getTest")
public String test(String name,String password) {
return "success";
}
3、Request Payload
content-type爲application/json,post請求參數位於body內,向後端傳遞一個json序列化的json字符串。後端要以一個類或者vo接受,以RequstBody註解
前端:http://xxx/getTest
後端:(參數可以使用類接收)
@PostMapping("/getTest")
public String test(@RequestBody 請求vo) {
return "success";
}
千里之行
始於足下