@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) {


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM