Swagger2匹配多個controller程式碼例項
阿新 • • 發佈:2020-09-21
方法一:使用多個controller的共同擁有的父類,即精確到兩個controller的上一級
@Bean public Docket createRestApi() { return new Docket(DocumentationType.SWAGGER_2) .apiInfo(apiInfo()) .select() .apis(RequestHandlerSelectors.basePackage("com.shubing")) .paths(PathSelectors.any()) .build(); }
方法二:指定所有controller的都實現的一個介面,比如@RestController
@Bean public Docket createRestApi() { return new Docket(DocumentationType.SWAGGER_2) .apiInfo(apiInfo()) .select() .apis(RequestHandlerSelectors.withClassAnnotation(RestController.class)) .paths(PathSelectors.any()) .build(); }
使用以下兩種,都是錯誤的
@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(); }
以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支援我們。