|
@@ -1,10 +1,12 @@
|
1
|
1
|
package com.yunzhi.marketing.config;
|
2
|
2
|
|
|
3
|
+import com.google.common.base.Predicate;
|
|
4
|
+import io.swagger.annotations.ApiOperation;
|
3
|
5
|
import org.springframework.context.annotation.Bean;
|
4
|
6
|
import org.springframework.context.annotation.Configuration;
|
|
7
|
+import springfox.documentation.RequestHandler;
|
5
|
8
|
import springfox.documentation.builders.ApiInfoBuilder;
|
6
|
9
|
import springfox.documentation.builders.PathSelectors;
|
7
|
|
-import springfox.documentation.builders.RequestHandlerSelectors;
|
8
|
10
|
import springfox.documentation.service.ApiInfo;
|
9
|
11
|
import springfox.documentation.service.Contact;
|
10
|
12
|
import springfox.documentation.spi.DocumentationType;
|
|
@@ -14,24 +16,34 @@ import springfox.documentation.swagger2.annotations.EnableSwagger2;
|
14
|
16
|
@Configuration
|
15
|
17
|
@EnableSwagger2
|
16
|
18
|
public class Swagger2Config {
|
17
|
|
-
|
18
|
|
-
|
19
|
|
- @Bean
|
20
|
|
- public Docket docket(){
|
21
|
|
- return new Docket(DocumentationType.SWAGGER_2).apiInfo(apiInfo()).select()
|
22
|
|
- .apis(RequestHandlerSelectors.basePackage("com.huiju.estateagents.controller"))
|
23
|
|
- .paths(PathSelectors.any()).build();
|
24
|
|
- }
|
25
|
|
- //构建api文档的详细信息函数
|
26
|
|
- private ApiInfo apiInfo(){
|
27
|
|
- return new ApiInfoBuilder()
|
28
|
|
- //页面标题
|
29
|
|
- .title("营销云 的 RESTful API")
|
30
|
|
- //版本号
|
31
|
|
- .version("1.0")
|
32
|
|
- //描述
|
33
|
|
- .description("API 描述")
|
34
|
|
- .build();
|
35
|
|
- }
|
36
|
|
-
|
|
19
|
+ @Bean
|
|
20
|
+ public Docket docket(){
|
|
21
|
+ Predicate<RequestHandler> predicate = new Predicate<RequestHandler>() {
|
|
22
|
+ @Override
|
|
23
|
+ public boolean apply(RequestHandler input) {
|
|
24
|
+ //只有添加了ApiOperation注解的method才在API中显示
|
|
25
|
+ if (input.isAnnotatedWith(ApiOperation.class)) {
|
|
26
|
+ return true;
|
|
27
|
+ } else {
|
|
28
|
+ return false;
|
|
29
|
+ }
|
|
30
|
+ }
|
|
31
|
+ };
|
|
32
|
+ return new Docket(DocumentationType.SWAGGER_2).groupName("docket").apiInfo(apiInfo()).select()
|
|
33
|
+ .apis(predicate)
|
|
34
|
+ .paths(PathSelectors.any()).build();
|
|
35
|
+ }
|
|
36
|
+ //构建api文档的详细信息函数
|
|
37
|
+ private ApiInfo apiInfo(){
|
|
38
|
+ return new ApiInfoBuilder()
|
|
39
|
+ //页面标题
|
|
40
|
+ .title("房产平台的 RESTful API")
|
|
41
|
+ //创建人
|
|
42
|
+ .contact(new Contact("房产平台","",""))
|
|
43
|
+ //版本号
|
|
44
|
+ .version("1.0")
|
|
45
|
+ //描述
|
|
46
|
+ .description("API 描述")
|
|
47
|
+ .build();
|
|
48
|
+ }
|
37
|
49
|
}
|