|
1 | 1 | package com.app.login.config;
|
2 | 2 |
|
| 3 | +// 导入必要的包 |
3 | 4 | import org.springframework.context.annotation.Bean;
|
4 | 5 | import org.springframework.context.annotation.Configuration;
|
5 | 6 | import org.springframework.context.annotation.Profile;
|
|
12 | 13 | import springfox.documentation.swagger2.annotations.EnableSwagger2;
|
13 | 14 |
|
14 | 15 | /**
|
15 |
| - * Created by Administrator on 2018/6/3 0003. |
| 16 | + * Swagger2配置类,用于配置Swagger2文档生成工具的相关设置。 |
| 17 | + * 创建者:Administrator |
| 18 | + * 创建时间:2018/6/3 0003 |
16 | 19 | */
|
17 |
| -@Configuration |
18 |
| -@EnableSwagger2 |
19 |
| -@Profile("!prod") |
| 20 | +@Configuration // 标记此类为配置类 |
| 21 | +@EnableSwagger2 // 启用Swagger2注解 |
| 22 | +@Profile("!prod") // 指定配置文件生效的环境,这里是非生产环境 |
20 | 23 | public class Swagger2Config {
|
| 24 | + |
| 25 | + // 定义一个Bean,用于创建Docket实例,Docket是Swagger提供的一个构建API文档的类 |
21 | 26 | @Bean
|
22 | 27 | public Docket createRestApi() {
|
| 28 | + // 创建Docket实例,指定文档类型为SWAGGER_2 |
23 | 29 | return new Docket(DocumentationType.SWAGGER_2)
|
24 |
| - .apiInfo(apiInfo()) |
25 |
| - .select() |
26 |
| - .apis(RequestHandlerSelectors.basePackage("com.app.login")) |
27 |
| - .paths(PathSelectors.any()) |
28 |
| - .build(); |
| 30 | + .apiInfo(apiInfo()) // 设置API文档的基本信息 |
| 31 | + .select() // 开始选择要包含在文档中的API |
| 32 | + .apis(RequestHandlerSelectors.basePackage("com.app.login")) // 指定扫描的基础包路径 |
| 33 | + .paths(PathSelectors.any()) // 匹配所有的路径 |
| 34 | + .build(); // 构建Docket实例 |
29 | 35 | }
|
30 | 36 |
|
| 37 | + // 定义一个方法,用于构建API文档的基本信息 |
31 | 38 | private ApiInfo apiInfo() {
|
| 39 | + // 使用ApiInfoBuilder构建ApiInfo对象 |
32 | 40 | return new ApiInfoBuilder()
|
33 |
| - .title("megadotnet use Swagger to build RESTful API") |
34 |
| - .description("megadotnet https://github.com/megadotnet/") |
35 |
| - .termsOfServiceUrl("https://github.com/megadotnet/") |
36 |
| - .contact("megadotnet") |
37 |
| - .version("1.0") |
38 |
| - .build(); |
| 41 | + .title("megadotnet use Swagger to build RESTful API") // 设置API文档的标题 |
| 42 | + .description("megadotnet https://github.com/megadotnet/") // 设置API文档的描述 |
| 43 | + .termsOfServiceUrl("https://github.com/megadotnet/") // 设置服务条款的URL |
| 44 | + .contact("megadotnet") // 设置联系人信息 |
| 45 | + .version("1.0") // 设置API文档的版本 |
| 46 | + .build(); // 构建ApiInfo对象 |
39 | 47 | }
|
40 |
| - |
41 | 48 | }
|
0 commit comments