swagger簡(jiǎn)介及使用

swagger的由來(lái)

  • 隨著互聯(lián)網(wǎng)技術(shù)的發(fā)展,現(xiàn)在的網(wǎng)站架構(gòu)基本都由原來(lái)的后端渲染,變成了:前端渲染、先后端分離的形態(tài),而且前端技術(shù)和后端技術(shù)在各自的道路上越走越遠(yuǎn)。
  • 前端和后端的唯一聯(lián)系,變成了API接口;API文檔變成了前后端開(kāi)發(fā)人員聯(lián)系的紐帶,變得越來(lái)越重要,swagger就是一款讓你更好的書(shū)寫(xiě)API文檔的框架。

同類技術(shù)

swagger生態(tài)圖

20170827202033991.png

swagger UI

示例


整個(gè)頁(yè)面.png

展開(kāi)界面


展開(kāi)界面.png

swagger-editor

就是一個(gè)在線編輯文檔說(shuō)明文件(swagger.json或swagger.yaml文件)的工具,以方便生態(tài)中的其他小工具(swagger-ui)等使用。 左邊編輯,右邊立馬就顯示出編輯內(nèi)容來(lái)。


swagger-editor.jpg

使用方法

  • 在pom中引入依賴

    <dependency>
      <groupId>com.spring4all</groupId>
          <artifactId>swagger-spring-boot-starter</artifactId>
      <version>1.8.0.RELEASE</version>
    </dependency>
    
  • 在應(yīng)用主類中增加@EnableSwagger2Doc注解

@SpringBootApplication
@EnableSwagger2Doc
    public class Springboot2Swagger2Application {
        public static void main(String[] args) {
        SpringApplication.run(Springboot2Swagger2Application.class, args);
    }
}

默認(rèn)情況下就能產(chǎn)生所有當(dāng)前SpringMVC加載的請(qǐng)求映射文檔
訪問(wèn)地址:http://localhost:8080/swagger-ui.html

  • 參數(shù)配置示例

    swagger.enabled=true
    swagger.title=spring-data-jpa module
    swagger.description=Starter for swagger 2.x
    swagger.license=Apache License, Version 2.0
    swagger.licenseUrl=https://www.apache.org/licenses/LICENSE-2.0.html
    swagger.termsOfServiceUrl=https://github.com/dyc87112/spring-boot-starter-    swagger
    swagger.contact.name=RanRan Tao
    swagger.contact.url=http://www.itdecent.cn/u/822585e5c69a
    swagger.contact.email=16422802@qq.com
    swagger.base-package=com.example.springdatajpa.controller
    swagger.base-path=/**
    swagger.exclude-path=/error, /ops/**
    

代碼

https://github.com/1094064939/SpringBootExample

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

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

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