整合Swagger2
demo:G:\学习资料\java\a-study\springboot\com.xufei.springboot\com-xufei-springboot-swagger2
# 1、导包
<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>
1
2
3
4
5
6
7
8
9
10
11
2
3
4
5
6
7
8
9
10
11
# 2、编写配置文件
@Configuration
@EnableSwagger2 //使能Swagger
public class SwaggerConfig {
//http://localhost:8080/swagger-ui.html 请求地址
@Bean
public Docket docket() {
return new Docket(DocumentationType.SWAGGER_2)
.apiInfo(apiInfo()) //这个方法的作用(生成接口的时候页面显示的信息)
.select() //表示的是选择那些路径和API生成文档
.apis(RequestHandlerSelectors.basePackage("com.xufei.springboot.controller")) //告诉他要扫描的接口存在的这个包
.paths(PathSelectors.any()) //对所有的API进行监控
.build(); //构建
}
/**
* 这个方法主要的作用是显示页面上的信息
*
* @return
*/
private ApiInfo apiInfo() {
return new ApiInfoBuilder()
.title("这里是测试Swagger2的功能文档") //文档的标题
.description("这里是NZ1904测试用的") //文档的描述
.contact("小飞飞") //作者
.version("v1.0") //版本
.build();
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# 3、测试
访问 http://ip:port/swagger-ui.html
最近更新: 2024/12/27, 16:46:15