@ApiParam @PathVariable @RequestParam

 

1.@ApiParam 顧名思義,是註解api的參數,也就是用於swagger提供開發者文檔,文檔中生成的註釋內容。

  

@ApiOperation( value = "編輯公告", notes = "編輯公告", httpMethod = "POST" )
    @RequestMapping( value = "/edit", method = RequestMethod.POST )
    public RequestResult edit(
            @ApiParam(name = "title", value = "公告標題", required = true) @RequestParam("title") String title,
            @ApiParam(name = "content", value = "公告內容", required = true) @RequestParam("content") String content){

2.@RequestParam,是獲取前端傳遞給後端的參數,可以是get方式,也可以是post方式。其中如果前端傳遞的參數和後端你接受的參數起的名字字段是一致的可以省略不寫,也可以直接寫@RequestParam String title,如果不一致一定要完整寫,不然獲取不到,如下面的bis_key就必須寫。

@ApiOperation( value = "編輯公告", notes = "編輯公告", httpMethod = "POST" )
    @RequestMapping( value = "/edit", method = RequestMethod.POST )
    public RequestResult edit(
            @ApiParam(name = "bis_key", value = "bis_key", required = true) String bisKey,
            @ApiParam(name = "title", value = "公告標題", required = true) @RequestParam String title,
            @ApiParam(name = "content", value = "公告內容", required = true)  String content,

3.@PathVariable,是獲取get方式,url後面參數,進行參數綁定

@ApiOperation(value = "刪除公告", notes = "刪除公告", httpMethod = "POST")
    @RequestMapping(value = "/delete/{bisKey}", method = RequestMethod.POST)
    public RequestResult remove(@ApiParam(name = "bisKey", value = "需要刪除的公告ids", required = true) @PathVariable String bisKey) {

@RequestPart與.@RequestParam

@RequestPart這個註解用在multipart/form-data表單提交請求的方法上。 
2.支持的請求方法的方式MultipartFile,屬於Spring的MultipartResolver類。這個請求是通過http協議傳輸的。 
3.@RequestParam也同樣支持multipart/form-data請求。 
4.他們最大的不同是,當請求方法的請求參數類型不再是String類型的時候。 
5.@RequestParam適用於name-valueString類型的請求域,@RequestPart適用於複雜的請求域(像JSON,XML)。
 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章