在Spring Boot中使用swagger-bootstrap-ui

swagger-bootstrap-ui是基于swagger接口api實現(xiàn)的一套UI,因swagger原生ui是上下結(jié)構(gòu)的,在瀏覽接口時不是很清晰,所以,swagger-bootstrap-ui是基于左右菜單風格的方式,適用與我們在開發(fā)后臺系統(tǒng)左右結(jié)構(gòu)這種風格類似,方便與接口瀏覽

GitHub:https://github.com/xiaoymin/Swagger-Bootstrap-UI

歡迎大家Watch,Fork,Star

界面預(yù)覽:

js.jpg

引入swagger

在pom.xml文件中引入swagger以及ui的jar包依賴

<dependency>
 <groupId>io.springfox</groupId>
 <artifactId>springfox-swagger2</artifactId>
 <version>2.7.0</version>
</dependency>
<!--引入ui包-->
<dependency>
 <groupId>com.github.xiaoymin</groupId>
 <artifactId>swagger-bootstrap-ui</artifactId>
 <version>1.7</version>
</dependency>

配置configuration

配置swagger的啟用配置文件,關(guān)鍵注解@EnableSwagger2

一下配置是支持接口分組的配置,如果沒有分組配置,只需要創(chuàng)建一個Docket即可

@Configuration
@EnableSwagger2
public class SwaggerConfiguration {
?
 @Bean
 public Docket createRestApi() {
 return new Docket(DocumentationType.SWAGGER_2)
 .apiInfo(apiInfo())
 .groupName("資源管理")
 .select()
 .apis(RequestHandlerSelectors.basePackage("com.lishiots.dc.baseinfo.ctl"))
 .paths(PathSelectors.any())
 .build();
 }
 @Bean
 public Docket createMonitorRestApi() {
 return new Docket(DocumentationType.SWAGGER_2)
 .apiInfo(apiInfo())
 .groupName("實時監(jiān)測")
 .select()
 .apis(RequestHandlerSelectors.basePackage("com.lishiots.dc.monitor.ctl"))
 .paths(PathSelectors.any())
 .build();
 }
 @Bean
 public Docket createActivitiRestApi() {
 return new Docket(DocumentationType.SWAGGER_2)
 .apiInfo(apiInfo())
 .groupName("工作流引擎")
 .select()
 .apis(RequestHandlerSelectors.basePackage("com.lishiots.dc.activiti.ctl"))
 .paths(PathSelectors.any())
 .build();
 }
?
 @Bean
 public Docket createBaseRestApi() {
 return new Docket(DocumentationType.SWAGGER_2)
 .apiInfo(apiInfo())
 .groupName("kernel模塊")
 .select()
 .apis(RequestHandlerSelectors.basePackage("com.lishiots.dc.kernel.ctl"))
 .paths(PathSelectors.any())
 .build();
 }
?
 @Bean
 public Docket createComplaintRestApi() {
 return new Docket(DocumentationType.SWAGGER_2)
 .apiInfo(apiInfo())
 .groupName("投訴管理")
 .select()
 .apis(RequestHandlerSelectors.basePackage("com.lishiots.dc.complaint.ctl"))
 .paths(PathSelectors.any())
 .build();
 }
?
 private ApiInfo apiInfo() {
 return new ApiInfoBuilder()
 .title("swagger RESTful APIs")
 .description("swagger RESTful APIs")
 .termsOfServiceUrl("http://www.test.com/")
 .contact("xiaoymin@foxmail.com")
 .version("1.0")
 .build();
 }
?
}

Controller層使用swagger注解

ctl代碼層:

@Api(tags = "banner管理")
@RestController
@RequestMapping("/api/bannerInfo")
public class BannerCtl {
 @Autowired
 private BannerInfoService service;
?
 @PostMapping("/query")
 @ApiOperation(value = "查詢banner",notes = "查詢banner")
 public Pagination<BannerInfo> bannerInfoQuery(){
 Pagination<BannerInfo> pagination = service.bannerInfoQuery();
 return pagination;
 }
}

接口訪問

在瀏覽器輸入:http://${host}:${port}/doc.html

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • Spring Cloud為開發(fā)人員提供了快速構(gòu)建分布式系統(tǒng)中一些常見模式的工具(例如配置管理,服務(wù)發(fā)現(xiàn),斷路器,智...
    卡卡羅2017閱讀 136,569評論 19 139
  • 貧窮的生物,連文明都會拋棄。
    木言寺閱讀 240評論 0 0
  • 一、概述 本文幾乎全部參考《Android開發(fā)藝術(shù)探索》(嚴重抄襲~)。不同的是,對書中實例做了兩方面的變更: 1...
    flycode閱讀 4,555評論 1 5
  • 很久以前看見有人用打賞這個功能,我其實內(nèi)心躍躍欲試,但是后來想想又放棄,沒有那么多勇氣,各種害怕。怕別人怎么想我,...
    妖精紅袖閱讀 500評論 4 1

友情鏈接更多精彩內(nèi)容