方法一:使用多個controller的共同擁有的父類,即精確到兩個controller的上一級
1
2
3
4
5
6
7
8
9
|
@Bean public Docket createRestApi() { return new Docket(DocumentationType.SWAGGER_2) .apiInfo(apiInfo()) .select() .apis(RequestHandlerSelectors.basePackage( "com.shubing" )) .paths(PathSelectors.any()) .build(); } |
方法二:指定所有controller的都實現的一個接口,比如@RestController
1
2
3
4
5
6
7
8
9
|
@Bean public Docket createRestApi() { return new Docket(DocumentationType.SWAGGER_2) .apiInfo(apiInfo()) .select() .apis(RequestHandlerSelectors.withClassAnnotation(RestController. class )) .paths(PathSelectors.any()) .build(); } |
使用以下兩種,都是錯誤的
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
@Bean public Docket createRestApi() { return new Docket(DocumentationType.SWAGGER_2) .apiInfo(apiInfo()) .select() .apis(RequestHandlerSelectors.basePackage( "com.shubing.*.controller" )) .paths(PathSelectors.any()) .build(); } @Bean public Docket createRestApi() { return new Docket(DocumentationType.SWAGGER_2) .apiInfo(apiInfo()) .select() .apis(RequestHandlerSelectors.basePackage( "com.shubing.course.controller" )) .apis(RequestHandlerSelectors.basePackage( "com.shubing.user.controller" )) .paths(PathSelectors.any()) .build(); } |
以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持服務器之家。
原文鏈接:https://www.cnblogs.com/acm-bingzi/p/swagger2-controller.html