【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

posted @ 2019-08-19 21:42  花生喂龙  阅读(3602)  评论(0编辑  收藏  举报