Swagger ----接口文档

Swagger 是一款RESTFUL接口的文档在线自动生成+功能测试功能软件

1.添加依赖
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.9.2</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.9.2</version>
</dependency>
2.开启 Swagger 功能
@EnableSwagger2
@SpringBootApplication
public class Application {.
3.配置 Swagger 文档摘要信息
@Configuration
public class SwaggerConfig {
@Bean
public Docket createRestApi() {
return new Docket(DocumentationType.SWAGGER_2) // 1.SWAGGER_2
.select()
.apis(RequestHandlerSelectors.basePackage("com.xxxx.controller")) // 2.设置扫描路径
.build();
}
}
4.调用接口访问
http://localhost:8080/swagger-ui.html

5.注解
- @Api()用于类;
表示标识这个类是swagger的资源 ,tags–表示说明 ,value–也是说明,可以使用tags替代
- @ApiOperation()用于方法;
表示一个http请求的操作,表示一个http请求的操作,value用于方法描述 ,notes用于提示内容
- @ApiParam()用于方法,参数,字段说明;name–参数名,value–参数说明 ,required–是否必填
表示对参数的添加元数据(说明或是否必填等)
- @ApiModel()用于类
表示对类进行说明,用于参数用实体类接收,value–表示对象名,description–描述
- @ApiModelProperty()用于方法,字段
表示对model属性的说明或者数据操作更改value–字段说明 ,name–重写属性名字 ,dataType–重写属性类型 ,required–是否必填 ,example–举例说明 ,hidden–隐藏
- @ApiIgnore()用于类,方法,方法参数
表示这个方法或者类被忽略
- @ApiImplicitParam() 用于方法
表示单独的请求参数
- @ApiImplicitParams() 用于方法,包含多个 @ApiImplicitParam

posted @ 2022-10-27 08:07  When?  阅读(85)  评论(0编辑  收藏  举报