乌海学校网站建设,wordpress 迁站,wordpress增加内存,麦壳云网站建设后端整合SwaggerKnife4j接口文档
接口文档介绍
什么是接口文档#xff1a;写接口信息的文档#xff0c;条接口包括#xff1a; 请求参数响应参数 错误码 接口地址接口名称请求类型请求格式备注 为什么需要接口文档 who用#xff1f;后端提供#xff0c;前后端都需要使用…后端整合SwaggerKnife4j接口文档
接口文档介绍
什么是接口文档写接口信息的文档条接口包括 请求参数响应参数 错误码 接口地址接口名称请求类型请求格式备注 为什么需要接口文档 who用后端提供前后端都需要使用有一个书面归档便于参考和查阅沉淀和维护便于前端和后端的开发联调的介质。后端接口文档前端在线测试作为工具提高开发速率 怎么做接口文档 手写比如腾讯笔记markdown笔记自动化接口文档生成根据项目代码生成完整的文档或在线联调工具SwaggerPostman侧重接管理apifoxapiposteolink Swagger接口的原理 自定义Swagger配置类定义需要生成接口文档的代码位置(controller)
项目中使用SwaggerKnife4j接口文档
Swagger官方https://swagger.io/项目中引入依赖groupIdio.springfox/groupIdartifactIdspringfox-swagger2/artifactIdversion2.7.0/version/dependencydependencygroupIdio.springfox/groupIdartifactIdspringfox-swagger-ui/artifactIdversion2.7.0/version/dependency自定义Swagger配置类在springBoot项目中使用springBoot的注解生成一个swagger配置的bean。 package com.yupi.usercenter.config;import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
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.EnableSwagger2WebMvc;/*** 自定义swagger的配置*/
Configuration
EnableSwagger2WebMvc // Swagger的开关表示已经启用Swagger
public class SwaggerConfig {Bean(value defaultApi2) //生成一个swagger的配置框架扫描到这个配置注入到swagger的对象中就可以初始化一个文档public Docket createRestApi(){return new Docket(DocumentationType.SWAGGER_2).apiInfo(apiInfo()).select()//标注控制器的位置.apis(RequestHandlerSelectors.basePackage(com.yupi.usercenter.controller)).paths(PathSelectors.any()).build();}/*** api信息* return*/private ApiInfo apiInfo() {return new ApiInfoBuilder().title(用户中心).contact(new Contact(whale, www.xxx.com, xxxqq.com)).description(这是用Swagger动态生成的用户中心接口文档).termsOfServiceUrl(NO terms of service).version(1.0).build();}
}若springboot versio2.6,需要添加以下配置 mvc:pathmatch:matching-strategy: ANT_PATH_MATCHER结果展示