1.post請求:
@RequestMapping(value = "childwatch/bind", method = RequestMethod.POST, produces = CTRL_PRODUCE) public ApiResp bind() { BindChildWatchApiReq req = getRequestObject(BindChildWatchApiReq.class); if (req == null) { return ApiResponse.error(CommonErrorCode.REQUEST_IS_NULL); } return childWatchApiService.bind(req); }
一般會有一個對象如
BindChildWatchApiReq,里面會有post請求的所有參數。
2.get請求:
看如下的一個接口,兩個參數會拼接到地址后面

后台代碼這樣接收

也可以用以下方法 @RequestParam 進行注解(使用另一個接口作為例子):
3.put請求:
get一般傳參數只進行查詢,對數據不做修改。put一般是修改數據。
如請求一個地址請求地址:http://ip:port/contextPath/api/v1/member/{memberId}/childwatch/phone
請求參數:watchPhone
在postman工具(一種進行get,post提交的工具)中這樣請求:http://127.0.0.1:10004/api/v3/zVadT9eSkQNz8zPY/childwatch/phone?rnd=ww
可以看出一共傳2個參數
memberId和watchPhone
java后台代碼如何接收呢,請看下面:
在地址欄里傳入的參數這邊可以用注解 @PathVariable獲得,watchPhone是在對象里獲得,和post一樣