赞
踩
本篇文章主要介绍如何在springboot3中整合knife4j。
注:springboot3系列示例代码采用3.2.2版本,jdk版本使用17
接口文档就是写接口信息的文档,每条接口包括:
一般是后端或者负责人来提供,后端和前端都要使用
knife4j是一个集Swagger2 和 OpenAPI3为一体的增强解决方案,帮助开发者快速聚合使用OpenAPI规范,快速生成API文档,并且提供一些额外的功能,比如:
- <!--引入knif4j-->
- <dependency>
- <groupId>com.github.xiaoymin</groupId>
- <artifactId>knife4j-openapi3-jakarta-spring-boot-starter</artifactId>
- <version>4.4.0</version>
- </dependency>
- # springdoc-openapi项目配置,访问地址:http://127.0.0.1:8080/doc.html
- springdoc:
- swagger-ui:
- path: /swagger-ui.html
- tags-sorter: alpha
- operations-sorter: alpha
- api-docs:
- path: /v3/api-docs
- group-configs:
- - group: 'default'
- paths-to-match: '/**'
- packages-to-scan: com.example.backend
-
- # knife4j的增强配置,不需要增强可以不配
- knife4j:
- enable: true
- setting:
- language: zh_cn
- spring:
- profiles:
- active: dev
- application:
- name: parentMaching
- #session 失效时间
- session:
- timeout: 86400
- server:
- port: 8080
- servlet:
- context-path: /api
- mybatis-plus:
- configuration:
- map-underscore-to-camel-case: false
- log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
- global-config:
- db-config:
- logic-delete-field: isDelete # 全局逻辑删除的实体字段名(since 3.3.0,配置后可以忽略不配置步骤2)
- logic-delete-value: 1 # 逻辑已删除值(默认为 1)
- logic-not-delete-value: 0 # 逻辑未删除值(默认为 0)
- # springdoc-openapi项目配置,访问地址:http://127.0.0.1:8080/doc.html
- springdoc:
- swagger-ui:
- path: /swagger-ui.html
- tags-sorter: alpha
- operations-sorter: alpha
- api-docs:
- path: /v3/api-docs
- group-configs:
- - group: 'default'
- paths-to-match: '/**'
- packages-to-scan: com.example.backend
-
- # knife4j的增强配置,不需要增强可以不配
- knife4j:
- enable: true
- setting:
- language: zh_cn
- package com.example.backend.config;
-
- import io.swagger.v3.oas.models.ExternalDocumentation;
- import io.swagger.v3.oas.models.OpenAPI;
- import io.swagger.v3.oas.models.info.Contact;
- import io.swagger.v3.oas.models.info.Info;
- import io.swagger.v3.oas.models.info.License;
- import org.springframework.context.annotation.Bean;
- import org.springframework.context.annotation.Configuration;
-
-
- /**
- * 自定义 Swagger 接口文档的配置
- * @author wang
- */
- @Configuration
- public class SwaggerConfig {
-
- @Bean
- public OpenAPI springShopOpenAPI() {
- return new OpenAPI()
- .info(new Info().title("伙伴匹配系统")
- .description("伙伴匹配系统API文档")
- .version("v1")
- .license(new License().name("Apache 2.0").url("http://springdoc.org")))
- .externalDocs(new ExternalDocumentation()
- .description("外部文档")
- .url("https://springshop.wiki.github.org/docs"));
- }
-
- }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。