Swagger2匹配多個controller代碼實例
更新時間:2020年09月19日 11:07:46 作者:賈樹丙
這篇文章主要介紹了Swagger2匹配多個controller代碼實例,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友可以參考下
方法一:使用多個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的都實現(xiàn)的一個接口,比如@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(); }
以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。
相關文章
解決springboot與springcloud版本兼容問題(附版本兼容表)
在基于spring boot搭建spring cloud時,創(chuàng)建eureka后啟動服務發(fā)生報錯,本文給大家介紹了解決springboot與springcloud版本兼容問題的幾種方案,需要的朋友可以參考下2024-02-02springboot如何獲取application.yml里值的方法
這篇文章主要介紹了springboot如何獲取application.yml里的值,文章圍繞主題相關自資料展開詳細的內容介紹,具有一定的參考價值,需要的小伙伴可以參考一下2022-04-04淺談Spring Boot: 接口壓測及簡要優(yōu)化策略
這篇文章主要介紹了淺談Spring Boot: 接口壓測及簡要優(yōu)化策略,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-09-09