溫馨提示×

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

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

Swagger中@ApiIgnore注解怎么用

發(fā)布時(shí)間:2021-10-21 09:03:55 來源:億速云 閱讀:1125 作者:小新 欄目:開發(fā)技術(shù)

這篇文章主要介紹了Swagger中@ApiIgnore注解怎么用,具有一定借鑒價(jià)值,感興趣的朋友可以參考下,希望大家閱讀完這篇文章之后大有收獲,下面讓小編帶著大家一起了解一下。

Swagger @ApiIgnore注解的使用

@ApiIgnore 可以用在類、方法上,方法參數(shù)中,用來屏蔽某些接口或參數(shù),使其不在頁面上顯示。

1、作用在類上時(shí),整個(gè)類都會(huì)被忽略

@ApiIgnore
@Api(tags = {"Xxx控制類"})
@RestController
@RequestMapping("/xxx")
public class XxxController {
  ......
}

隱藏某個(gè)類還可以用@Api注解自帶的hidden屬性:

@Api(value = "xxx", tags = "xxx",hidden = true)

當(dāng)hidden為true時(shí),該類隱藏。

2、當(dāng)作用在方法上時(shí),方法將被忽略

@ApiIgnore
@ApiOperation(value = "xxx", httpMethod = "POST", notes = "xxx")
@ApiImplicitParams({
  @ApiImplicitParam(name = "xxx", value = "xxx", paramType = "query", dataType = "String", required = true)
})
@PostMapping("/xxx")
public Result importCarryEquExcel(String xxx) {
    ......
}

隱藏某個(gè)方法還可以用@APIOperation注解自帶的hidden屬性:

@ApiOperation(value = "xxx", httpMethod = "GET", notes = "xxx",hidden = true)

當(dāng)hidden為true時(shí),該方法隱藏。

3、作用在參數(shù)上時(shí),單個(gè)具體的參數(shù)會(huì)被忽略

public String abc(@ApiIgnore String a, String b, String c){
    return "a" + "b" + "c";
  }

補(bǔ)充:

4、 在實(shí)體類中忽略不需要字段的方式

(1)用@ApiModelProperty注解自帶的hidden屬性:

@ApiModelProperty(value = "xxxid", required = true,hidden = true)
    private Long id;

(2)使用@JsonIgnore注解:

@ApiModelProperty(value = "xxxid", required = true)
    @JsonIgnore
    private Long id;

包名:

import  com.fasterxml.jackson.annotation.JsonIgnore;

Swagger中的常用注解

使用swagger時(shí)

  • @ApiOperation表示生成API文檔

  • @Apiignore表示忽略生成

@ApiIgnore 可以用在類、方法上,方法參數(shù)中,用來屏蔽某些接口或參數(shù),使其不在頁面上顯示。

1、作用在類上時(shí),整個(gè)類都會(huì)被忽略

@ApiIgnore
@Api(tags = {"Xxx控制類"})
@RestController
@RequestMapping("/xxx")
public class XxxController {
        ......
}

隱藏某個(gè)類還可以用@Api注解自帶的hidden屬性:

@Api(value = "xxx", tags = "xxx",hidden = true)
當(dāng)hidden為true時(shí),該類隱藏

2、當(dāng)作用在方法上時(shí),方法將被忽略

@ApiIgnore
@ApiOperation(value = "xxx", httpMethod = "POST", notes = "xxx")
@ApiImplicitParams({
        @ApiImplicitParam(name = "xxx", value = "xxx", paramType = "query", dataType = "String", required = true)
})
@PostMapping("/xxx")
public Result importCarryEquExcel(String xxx) {
                ......
}

隱藏某個(gè)方法還可以用@APIOperation注解自帶的hidden屬性

@ApiIgnore
@ApiOperation(value = "xxx", httpMethod = "POST", notes = "xxx")
@ApiImplicitParams({
        @ApiImplicitParam(name = "xxx", value = "xxx", paramType = "query", dataType = "String", required = true)
})
@PostMapping("/xxx")
public Result importCarryEquExcel(String xxx) {
                ......
}

隱藏某個(gè)方法還可以用@APIOperation注解自帶的hidden屬性:

@ApiOperation(value = "xxx", httpMethod = "GET", notes = "xxx",hidden = true)

當(dāng)hidden為true時(shí),該方法隱藏

3、作用在參數(shù)上時(shí),單個(gè)具體的參數(shù)會(huì)被忽略

public String abc(@ApiIgnore String a, String b, String c){
    return "a" + "b" + "c";
  }

感謝你能夠認(rèn)真閱讀完這篇文章,希望小編分享的“Swagger中@ApiIgnore注解怎么用”這篇文章對(duì)大家有幫助,同時(shí)也希望大家多多支持億速云,關(guān)注億速云行業(yè)資訊頻道,更多相關(guān)知識(shí)等著你來學(xué)習(xí)!

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

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

AI