springboot 整合swagger2 ,搭建 RESTful API 在线文档

版权声明:如果觉得好的话,不防点个赞,那点你们认为不对或是需要补充,可以留言啊!本人原创,未经允许不得转载!! https://blog.csdn.net/qq_28289405/article/details/86508283

1、pom 文件引入jar包

        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger2</artifactId>
            <version>2.7.0</version>
        </dependency>
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger-ui</artifactId>
            <version>2.7.0</version>
        </dependency>

2、生成文档的注释

swagger2 通过注解来生成api接口文档,文档信息包括接口名、请求方法、参数、返回信息等。

注解:

@Api

修饰整个类,用于描述Controller类

@ApiOperation

描述类的方法,或者说是一个接口
@ApiParam 单个参数描述
@ApiModel 用对象来接受参数
@ApiProperty 用对象接收参数时,描述对象的一个字段
@ApiResponse HTTP响应的一个描述
@ApiResponses HTTP响应的整体描述
@ApiIgnore 忽略这个api
@ApiError 发生错误返回的信息
@ApiParamImplicit 一个请求参数
@ApiParamsImplicit 多个请求参数

猜你喜欢

转载自blog.csdn.net/qq_28289405/article/details/86508283