Skip to content

Commit fde08e1

Browse files
committed
fixed: added comment Swagger2Config
1 parent e1f93c4 commit fde08e1

File tree

1 file changed

+23
-16
lines changed

1 file changed

+23
-16
lines changed
Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.app.login.config;
22

3+
// 导入必要的包
34
import org.springframework.context.annotation.Bean;
45
import org.springframework.context.annotation.Configuration;
56
import org.springframework.context.annotation.Profile;
@@ -12,30 +13,36 @@
1213
import springfox.documentation.swagger2.annotations.EnableSwagger2;
1314

1415
/**
15-
* Created by Administrator on 2018/6/3 0003.
16+
* Swagger2配置类,用于配置Swagger2文档生成工具的相关设置。
17+
* 创建者:Administrator
18+
* 创建时间:2018/6/3 0003
1619
*/
17-
@Configuration
18-
@EnableSwagger2
19-
@Profile("!prod")
20+
@Configuration // 标记此类为配置类
21+
@EnableSwagger2 // 启用Swagger2注解
22+
@Profile("!prod") // 指定配置文件生效的环境,这里是非生产环境
2023
public class Swagger2Config {
24+
25+
// 定义一个Bean,用于创建Docket实例,Docket是Swagger提供的一个构建API文档的类
2126
@Bean
2227
public Docket createRestApi() {
28+
// 创建Docket实例,指定文档类型为SWAGGER_2
2329
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实例
2935
}
3036

37+
// 定义一个方法,用于构建API文档的基本信息
3138
private ApiInfo apiInfo() {
39+
// 使用ApiInfoBuilder构建ApiInfo对象
3240
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对象
3947
}
40-
4148
}

0 commit comments

Comments
 (0)