国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

Swagger + Knife4j 接口文檔的整合

這篇具有很好參考價值的文章主要介紹了Swagger + Knife4j 接口文檔的整合。希望對大家有所幫助。如果存在錯誤或未考慮完全的地方,請大家不吝賜教,您也可以點擊"舉報違法"按鈕提交疑問。

Swagger 接口文檔的整合:

  1. 引入依賴(Swagger 或 Knife4j)。
  2. 自定義 Swagger 配置類。
  3. 定義需要生成接口文檔的代碼位置(Controller)。
  4. 注意:線上環(huán)境不要把接口暴露出去?。。】梢酝ㄟ^在 SwaggerConfig 配置文件開頭加上 @Profile({“dev”, “test”}) 限定配置僅在部分環(huán)境開啟。
  5. 啟動接口文檔。
  6. 可以通過在 controller 方法上添加 @Api、@ApiImplicitParam(name = “name”,value = “姓名”,required = true) @ApiOperation(value = “向客人問好”) 等注解來自定義生成的接口描述信息

Swagger

Swagger 官網

  1. 依賴引入
      <!-- swagger 接口文檔 -->
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger2</artifactId>
            <version>2.9.2</version>
        </dependency>
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger-ui</artifactId>
            <version>2.9.2</version>
        </dependency>
  1. 創(chuàng)建 config 文件
package com.heo.matchmatebackend.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * 自定義 Swagger 接口文檔的配置
 */
@Configuration // 配置類
@EnableSwagger2 // 開啟 swagger2 的自動配置
@Profile({"dev", "test"})   //版本控制訪問
public class SwaggerConfig {
    @Bean(value = "defaultApi2")
    public Docket docket() {
        // 創(chuàng)建一個 swagger 的 bean 實例
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                // 配置接口信息
                .select() // 設置掃描接口
                // 配置如何掃描接口
                .apis(RequestHandlerSelectors
                                //.any() // 掃描全部的接口,默認
                                //.none() // 全部不掃描
                                .basePackage("com.heo.matchmatebackend.controller") // 掃描指定包下的接口,最為常用
                        //.withClassAnnotation(RestController.class) // 掃描帶有指定注解的類下所有接口
                        //.withMethodAnnotation(PostMapping.class) // 掃描帶有只當注解的方法接口
                )
                .paths(PathSelectors
                                .any() // 滿足條件的路徑,該斷言總為true
                        //.none() // 不滿足條件的路徑,該斷言總為false(可用于生成環(huán)境屏蔽 swagger)
                        //.ant("/user/**") // 滿足字符串表達式路徑
                        //.regex("") // 符合正則的路徑
                )
                .build();
    }

    /**
     * api 信息
     * @return
     */
    private ApiInfo apiInfo() {
        Contact contact = new Contact(
                "heo", // 作者姓名
                "https://blog.csdn.net/XiugongHao", // 作者網址
                "xxx@qq.com"); // 作者郵箱
        return new ApiInfoBuilder()
                .title("matchmate") // 標題
                .description("matchmate 接口文檔") // 描述
                .termsOfServiceUrl("https://blog.csdn.net/XiugongHao") // 跳轉連接
                .version("1.0") // 版本
                .contact(contact)
                .build();
    }
}

  1. yml 配置(如果 springboot version >= 2.6,需要添加如下配置 pathmatch)
spring:
  mvc:
    pathmatch:
      matching-strategy: ant_path_matcher
  profiles:
    active: dev
  1. 最后運行啟動。

http://localhost:8080/api/swagger-ui.html

Swagger + Knife4j 接口文檔的整合,java

Knife4j

Knife4j 官網

  1. 依賴引入。
        <!-- knife4j 接口文檔 -->
        <dependency>
            <groupId>com.github.xiaoymin</groupId>
            <artifactId>knife4j-spring-boot-starter</artifactId>
            <version>2.0.7</version>
        </dependency>
  1. config 文件配置。
package com.heo.matchmatebackend.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * 自定義 Swagger 接口文檔的配置
 */
@Configuration // 配置類
@EnableSwagger2 // 開啟 swagger2 的自動配置
@Profile({"dev", "test"})   //版本控制訪問
public class SwaggerConfig {
    @Bean(value = "defaultApi2")
    public Docket docket() {
        // 創(chuàng)建一個 swagger 的 bean 實例
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                // 配置接口信息
                .select() // 設置掃描接口
                // 配置如何掃描接口
                .apis(RequestHandlerSelectors
                                //.any() // 掃描全部的接口,默認
                                //.none() // 全部不掃描
                                .basePackage("com.heo.matchmatebackend.controller") // 掃描指定包下的接口,最為常用
                        //.withClassAnnotation(RestController.class) // 掃描帶有指定注解的類下所有接口
                        //.withMethodAnnotation(PostMapping.class) // 掃描帶有只當注解的方法接口
                )
                .paths(PathSelectors
                                .any() // 滿足條件的路徑,該斷言總為true
                        //.none() // 不滿足條件的路徑,該斷言總為false(可用于生成環(huán)境屏蔽 swagger)
                        //.ant("/user/**") // 滿足字符串表達式路徑
                        //.regex("") // 符合正則的路徑
                )
                .build();
    }

    /**
     * api 信息
     * @return
     */
    private ApiInfo apiInfo() {
        Contact contact = new Contact(
                "heo", // 作者姓名
                "https://blog.csdn.net/XiugongHao", // 作者網址
                "xxx@qq.com"); // 作者郵箱
        return new ApiInfoBuilder()
                .title("matchmate") // 標題
                .description("matchmate 接口文檔") // 描述
                .termsOfServiceUrl("https://blog.csdn.net/XiugongHao") // 跳轉連接
                .version("1.0") // 版本
                .contact(contact)
                .build();
    }
}

  1. yml 配置。
spring:
  mvc:
    pathmatch:
      matching-strategy: ant_path_matcher
  profiles:
    active: dev
  1. 啟動。

http://localhost:8080/api/doc.html#/home

Swagger + Knife4j 接口文檔的整合,java文章來源地址http://www.zghlxwxcb.cn/news/detail-808447.html

到了這里,關于Swagger + Knife4j 接口文檔的整合的文章就介紹完了。如果您還想了解更多內容,請在右上角搜索TOY模板網以前的文章或繼續(xù)瀏覽下面的相關文章,希望大家以后多多支持TOY模板網!

本文來自互聯(lián)網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。如若轉載,請注明出處: 如若內容造成侵權/違法違規(guī)/事實不符,請點擊違法舉報進行投訴反饋,一經查實,立即刪除!

領支付寶紅包贊助服務器費用

相關文章

  • Spring Boot3整合knife4j(swagger3)

    Spring Boot3整合knife4j(swagger3)

    目錄 1.前置條件 2.導依賴 3.配置 已經初始化好一個spring boot項目且版本為3X,項目可正常啟動。 作者版本為3.2.2 初始化教程: 新版idea創(chuàng)建spring boot項目-CSDN博客 https://blog.csdn.net/qq_62262918/article/details/135785412?spm=1001.2014.3001.5501 knife4j官網: Knife4j · 集Swagger2及OpenAPI3為一體的增強

    2024年01月23日
    瀏覽(30)
  • Spring Boot 2.6 以上整合 Swagger + Knife4j 報錯

    Spring Boot 2.6 以上整合 Swagger + Knife4j 報錯

    這個問題主要出現在 Spring Boot 2.6 及以后,只要是 Spring Boot 2.6 引入的新 PathPatternParser 導致的。 兩種解決辦法 Path匹配策略切換回 ??ant_path_matcher ? 添加下面這個Bean的定義

    2024年01月17日
    瀏覽(37)
  • knife4j接口文檔

    knife4j接口文檔

    knife4j是為Java MVC框架集成Swagger生成Api文檔的增強解決方案,前身是swagger-bootstrap-ui,取名knife4j是希望它能像一把匕首一樣小巧,輕量,并且功能強悍!其底層是對Springfox的封裝,使用方式也和Springfox一致,只是對接口文檔UI進行了優(yōu)化。 核心功能 : 文檔說明 :根據Swagger的規(guī)范說明

    2023年04月08日
    瀏覽(19)
  • SpringBoot3中Swagger整合knife4j和springdoc的配置說明

    ? springboot3開始javax包改成了jakarta,而swagger-oas等包中依然使用的是javax所以報錯。另外springfox已經過時了,兩年沒更新了,并且不支持OpenAPI3 標準,而SpringBoot3只支持OpenAPI3規(guī)范,所以要遷移到springdoc Knife4J是一款基于Swagger快速生成API文檔和調試平臺的開源工具,它可以輕松地

    2024年02月04日
    瀏覽(33)
  • Spring Boot 集成 API 文檔 - Swagger、Knife4J、Smart-Doc

    Spring Boot 集成 API 文檔 - Swagger、Knife4J、Smart-Doc

    Swagger 作為 API 設計和文檔的強大工具,是一個由專門的工具集合支持的框架,它在整個 API 的生命周期中發(fā)揮作用,從設計和文檔,到測試和部署。通過提供可視化界面,Swagger 讓開發(fā)人員和最終用戶都能清晰地理解和操作 API。 使用建議:筆者建議優(yōu)先考慮 Knife4J,它已經能

    2024年01月22日
    瀏覽(22)
  • 【SpringBoot筆記42】SpringBoot集成knife4j生成接口文檔

    這篇文章,主要介紹SpringBoot如何集成knife4j及生成接口文檔。 目錄 一、knife4j接口文檔生成器 1.1、接口文檔工具介紹 1.2、引入依賴

    2024年02月05日
    瀏覽(22)
  • Springboot 2.7 集成 Swagger 增強版接口框架 Knife4j 4.3 + springdoc OpenApi 3.0

    Springboot 2.7 集成 Swagger 增強版接口框架 Knife4j 4.3 + springdoc OpenApi 3.0

    Swagger 作為一款服務端接口文檔自動生成框架,早已深入人心,并且在市場上得到了廣泛的應用。然而,Swagger 3.0 也就是 OpenApi 3.0 規(guī)范發(fā)布之后便停止了更新維護,出道就是巔峰。Knife4j 作為 Swagger 的增強版,是對 Swagger UI 做了優(yōu)化,同時還有很多增強的功能。伴隨著 Swagge

    2024年02月08日
    瀏覽(33)
  • 【SpringBoot】Swagger和knife4j的使用

    【SpringBoot】Swagger和knife4j的使用

    springboot筆記集合: springboot筆記合計 沒用的廢話理論不多說,會用就完了 Swagger 是一種開源的API描述語言,就是描述API的, 同時Swagger還提供了一組工具(也叫Swagger),可以幫助開發(fā)人員自動生成API文檔、測試API并與其他系統(tǒng)集成。 Knife4j是基于Swagge語言延伸的另一組api工具,簡

    2024年02月10日
    瀏覽(20)
  • Spring Cloud Gateway + Knife4j 4.3 實現微服務網關聚合接口文檔

    Spring Cloud Gateway + Knife4j 4.3 實現微服務網關聚合接口文檔

    ?? 作者主頁: 有來技術 ?? 開源項目: youlai-mall ?? vue3-element-admin ?? youlai-boot ?? 倉庫主頁: Gitee ?? Github ?? GitCode ?? 歡迎點贊 ?? 收藏 ?留言 ?? 如有錯誤敬請糾正! youlai-mall 開源微服務商城新版本基于 Spring Boot 3 和 Java 17,同時采用 Knife4j 4.3。與以前版本不同的是

    2024年02月08日
    瀏覽(21)
  • SpringBoot 整合knife4j

    SpringBoot 整合knife4j

    Knife4j是一款基于Swagger 2的在線API文檔框架 添加依賴 創(chuàng)建 Swagger 配置依賴 application.yml配置文件 響應參數 tips: http://127.0.0.1:8080/doc.html 這里端口,就是你運行項目的端口 springboot 中 knife4j的完整參數如下: 接口添加作者 添加作者有倆種方式 在方法上使用注解 @ApiOperationSupport

    2024年02月14日
    瀏覽(23)

覺得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請作者喝杯咖啡吧~博客贊助

支付寶掃一掃領取紅包,優(yōu)惠每天領

二維碼1

領取紅包

二維碼2

領紅包