1. 程式人生 > >@ApiParam @PathVariable @RequestParam三者區別

@ApiParam @PathVariable @RequestParam三者區別

@ApiParam @PathVariable @RequestParam三者區別

[email protected] 顧名思義,是註解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){

[email protected],是獲取前端傳遞給後端的引數,可以是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,

[email protected],是獲取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) {