getParm
@GetMapping("getParm")
public Result getParm(String id){
System.out.println();
return ResultFactory.success(id);
}
等同於 ==
bodyParm
@PostMapping("bodyParm") public Result bodyParm(@RequestBody String id){ System.out.println(id); return ResultFactory.success(id); }
bodyParm2
@PostMapping(path = "bodyParm2",consumes = MediaType.APPLICATION_JSON_VALUE) public Result bodyParm2(@RequestBody String id){ System.out.println(id); return ResultFactory.success(id); }
總結
1、form-data:
就是http請求中的multipart/form-data,它會將表單的數據處理爲一條消息,以標籤爲單元,用分隔符分開。既可以上傳鍵值對,也可以上傳文件。當上傳的字段是文件時,會有Content-Type來說明文件類型;content-disposition,用來說明字段的一些信息;
form的enctype屬性爲編碼方式,
常用有兩種:application/x-www-form-urlencoded和multipart/form-data,默認爲application/x-www-form-urlencoded。
當action爲get時候,瀏覽器用x-www-form-urlencoded的編碼方式把form數據轉換成一個字串(name1=value1&name2=value2...),然後把這個字串append到url後面,用?分割,加載這個新的url。
當action爲post時候,瀏覽器把form數據封裝到http body中,然後發送到server。如果沒有type=file的控件,用默認的application/x-www-form-urlencoded就可以了。
但是如果有type=file的話,就要用到multipart/form-data了。瀏覽器會把整個表單以控件爲單位分割,併爲每個部分加上Content-Disposition(form-data或者file)、Content-Type(默認爲text/plain)、name(控件name)等信息,並加上分割符(boundary)。
1. @PostMapping 未指定提交格式的: url , form-data,x-www-form-urlencoded 均可以獲取到值, 其他方式不行
2. @PostMapping 未指定提交格式時, 但參數使用@RequestBody 設定的, 則必須使用 x-www-form-urlencoded ,或者 raw (json,text,請求體格式),後端接收的數據爲整個請求體的內容數據
3. @POSTMapping 未指定提交格式是,但參數使用@NotNull 設定是, 則必須使用url , form-data,x-www-form-urlencoded 均可以獲取到值, 其他方式不行
4. @GetMapping 未指定提交格式式, 但參數使用@NotNull 設定時, 則必須使用url 或者 form-data 可以獲取到值, 其他方式不行