springfox-swagger之swagger-bootstrap-ui


swagger-bootstrap-ui是國內的一個swagger開源項目,從發起到現在已經有三年了。
初次體驗了一下,覺得還是挺不錯的,就如當初使用mybatis-plus那樣,因為有了mybatis的基礎,所以過渡到mybatis-plus很沒有壓力。
現在由swagger2到swagger-bootstrap-ui也是沒有壓力的,基本上參考官方文檔就能弄好了。

目前我應用在我個人的博客項目上,效果如圖:

關於如何搭建步驟,我主要是參考官方文檔,我本次寫的就作為官方文檔的一點補充:

一、添加Maven依賴

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

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

二、編寫配置類

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import com.github.xiaoymin.swaggerbootstrapui.annotations.EnableSwaggerBootstrapUI;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

@Configuration
@EnableSwagger2
@EnableSwaggerBootstrapUI
public class SwaggerConfiguration {

 @Bean
 public Docket createRestApi() {
     return new Docket(DocumentationType.SWAGGER_2)
     .apiInfo(apiInfo())
     .select()
     .apis(RequestHandlerSelectors.basePackage("com.blog.springboot"))
     .paths(PathSelectors.any())
     .build();
 }

 private ApiInfo apiInfo() {
     return new ApiInfoBuilder()
     .title("swagger-bootstrap-ui RESTful APIs")
     .description("swagger-bootstrap-ui")
     .termsOfServiceUrl("http://www.youcongtech.com")
     .contact("developer@mail.com")
     .version("1.1")
     .build();
 }
}

三、去下載對應的前端資源

下載地址為:https://github.com/xiaoymin/Swagger-Bootstrap-UI/tags ,如下圖所示:

四、下載完畢后解壓並將swagger-bootstrap-ui放到springboot項目職工的src/main/resources目錄下

步驟如圖:
找到這個文件夾

並將其遷移到springboot對應的目錄

五、整個流程完成后,啟動應用,訪問地址為http://IP:Port//doc.html

參考資料如下:
swagger-bootstrap-ui文檔:http://doc.xiaominfo.com


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM