Spring MVC+ swagger-bootstrap-ui生成接口文檔

做爲一個天秤座的程序員,雖然很早就知道 swagger,而且也知道它的好處,可是沒法忍受那醜陋的顯示界面,因此之前一直都採用markdown來書寫api文檔,前一段時間逛逛碼雲發現了swagger-bootstrap-ui這個好東西,生成api文檔真的是簡潔美觀。前端

Swagger-Bootstrap-UI是Swagger的前端UI實現,採用jQuery+bootstrap實現,目的是替換Swagger默認的UI實現Swagger-UI,使文檔更友好一點兒...。Swagger-Bootstrap-UI項目地址https://git.oschina.net/xiaoym/swagger-bootstrap-uijava

依賴配置:git

<dependency>
 <groupId>io.springfox</groupId>
 <artifactId>springfox-swagger2</artifactId>
 <version>2.2.2</version>
</dependency>

<!--swagger-bootstrap-ui-->
<dependency>
  <groupId>com.github.xiaoymin</groupId>
  <artifactId>swagger-bootstrap-ui</artifactId>
  <version>1.6</version>
</dependency>

若是項目採用SpringBoot則直接參考swagger-bootstrap-ui提供的demo,其實Spring MVC項目使用swagger-bootstrap-ui也差很少,只須要在Spring mvc的xml中加入下面兩行配置,其餘徹底相同,改代碼是讓項目自動去掃描swagger-bootstrap-ui的controller程序員

<context:component-scan base-package="springfox.petstore.controller"/>
<bean name="applicationSwaggerConfig" class="com.hunnao.config.SwaggerConfiguration"/>

SwaggerConfiguration類也是來自swagger-bootstrap-ui下的說明,而後在controller接口層加註解參考swagger-bootstrap-ui提供的demo便可github

相關文章
相關標籤/搜索