|
|
|
|
1
|
package com.huiju.estateagents.config;
|
1
|
package com.huiju.estateagents.config;
|
2
|
|
2
|
|
|
|
3
|
+import com.google.common.base.Predicate;
|
|
|
4
|
+import io.swagger.annotations.ApiOperation;
|
3
|
import org.springframework.context.annotation.Bean;
|
5
|
import org.springframework.context.annotation.Bean;
|
4
|
import org.springframework.context.annotation.Configuration;
|
6
|
import org.springframework.context.annotation.Configuration;
|
|
|
7
|
+import springfox.documentation.RequestHandler;
|
5
|
import springfox.documentation.builders.ApiInfoBuilder;
|
8
|
import springfox.documentation.builders.ApiInfoBuilder;
|
6
|
import springfox.documentation.builders.PathSelectors;
|
9
|
import springfox.documentation.builders.PathSelectors;
|
7
|
import springfox.documentation.builders.RequestHandlerSelectors;
|
10
|
import springfox.documentation.builders.RequestHandlerSelectors;
|
|
|
|
|
18
|
|
21
|
|
19
|
@Bean
|
22
|
@Bean
|
20
|
public Docket docket(){
|
23
|
public Docket docket(){
|
21
|
- return new Docket(DocumentationType.SWAGGER_2).apiInfo(apiInfo()).select()
|
|
|
22
|
- .apis(RequestHandlerSelectors.basePackage("com.huiju.estateagents.controller"))
|
|
|
|
|
24
|
+ Predicate<RequestHandler> predicate = new Predicate<RequestHandler>() {
|
|
|
25
|
+ @Override
|
|
|
26
|
+ public boolean apply(RequestHandler input) {
|
|
|
27
|
+ //只有添加了ApiOperation注解的method才在API中显示
|
|
|
28
|
+ if (input.isAnnotatedWith(ApiOperation.class)) {
|
|
|
29
|
+ return true;
|
|
|
30
|
+ } else {
|
|
|
31
|
+ return false;
|
|
|
32
|
+ }
|
|
|
33
|
+ }
|
|
|
34
|
+ };
|
|
|
35
|
+ return new Docket(DocumentationType.SWAGGER_2).groupName("docket").apiInfo(apiInfo()).select()
|
|
|
36
|
+ .apis(predicate)
|
23
|
.paths(PathSelectors.any()).build();
|
37
|
.paths(PathSelectors.any()).build();
|
24
|
}
|
38
|
}
|
25
|
//构建api文档的详细信息函数
|
39
|
//构建api文档的详细信息函数
|