溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

如何理解ApiOperation注解

發(fā)布時間:2021-09-29 16:55:39 來源:億速云 閱讀:262 作者:iii 欄目:大數(shù)據(jù)

本篇內(nèi)容主要講解“如何理解ApiOperation注解”,感興趣的朋友不妨來看看。本文介紹的方法操作簡單快捷,實用性強。下面就讓小編來帶大家學(xué)習(xí)“如何理解ApiOperation注解”吧!

1.@ApiParam 顧名思義,是注解api的參數(shù),也就是用于swagger提供開發(fā)者文檔,文檔中生成的注釋內(nèi)容。

  

@ApiOperation( value = "編輯公告", notes = "編輯公告", httpMethod = "POST" )
    @RequestMapping( value = "/edit", method = RequestMethod.POST )
    public RequestResult edit(
            @ApiParam(name = "title", value = "公告標(biāo)題", required = true) @RequestParam("title") String title,
            @ApiParam(name = "content", value = "公告內(nèi)容", required = true) @RequestParam("content") String content){
2.@RequestParam,是獲取前端傳遞給后端的參數(shù),可以是get方式,也可以是post方式。其中如果前端傳遞的參數(shù)和后端你接受的參數(shù)起的名字字段是一致的可以省略不寫,也可以直接寫@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 = "公告標(biāo)題", required = true) @RequestParam String title,
            @ApiParam(name = "content", value = "公告內(nèi)容", required = true)  String content,
3.@PathVariable,是獲取get方式,url后面參數(shù),進(jìn)行參數(shù)綁定

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

到此,相信大家對“如何理解ApiOperation注解”有了更深的了解,不妨來實際操作一番吧!這里是億速云網(wǎng)站,更多相關(guān)內(nèi)容可以進(jìn)入相關(guān)頻道進(jìn)行查詢,關(guān)注我們,繼續(xù)學(xué)習(xí)!

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI