【Swagger2】【3】API注解詳解,以及注解常用參數配置


前言:

@Api,@ApiOperation,@ApiImplicitParam,@ApiModelProperty,@ApiIgnore

正文:

一,Controller層

@ApiIgnore
@CrossOrigin(origins = "*")
@RestController
@Api(tags = {"文章接口"})
public class ArticleController {

    @ApiIgnore
    @ApiOperation(value = "文章詳情")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "id", value = "文章編號", required = true, dataType = "String", paramType = "query", example="12345"),
    })
    @RequestMapping(value = "article", method = RequestMethod.GET)
    public Result<Article> getArticleInfo(@ApiIgnore String id) {
        return this.theService.getArticleInfo(id);
    }
}

 

 

@Api:作用在類上,用來標注該類具體實現內容。

參數:

1,tags:該類的名稱
2,description:描述該類的作用

 

@ApiOperation:表示一個http請求的操作

參數:

1,value : 接口名稱

 

@ApiImplicitParam:接口的單個請求參數 ,根據需要選擇

參數:

1,name :參數名 

2,value : 描述參數名 

3,required : 該參數是否必填

4,dataType :參數的數據類型 

4,example:舉例 

6, paramType :查詢參數類型。這里有幾種形式:

類型 作用
path 以地址的形式提交數據
query 直接跟參數完成自動映射賦值
body 以流的形式提交 僅支持POST
header  參數在request headers 里邊提交
form 以form表單的形式提交 僅支持POST

 

@ApiIgnore

表示忽略該方法、類、參數,不顯示在swagger-ui.html上

 

二,如果傳入的參數是用實體類接收的

public class AddVo {
    @ApiModelProperty(name="province", value="所在省", required=true)
    private String province;

    @ApiModelProperty(name="city", value="所在市", required=true)
    private String city;
}

@ApiModelProperty:同@ApiImplicitParam一致

參考博客:

SwaggerAPI注解詳解,以及注解常用參數配置 - 都讓你們叫老了的博客 - CSDN博客
https://blog.csdn.net/java_yes/article/details/79183804

@ApiIgnore 注解的用法

https://blog.csdn.net/Hu531053/article/details/103662714


免責聲明!

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



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