当前位置: 首页 > news >正文

通用集团网站模板成都网站seo

通用集团网站模板,成都网站seo,做h5的软件,国外服务器做网站不能访问我的飞书:https://rvg7rs2jk1g.feishu.cn/docx/TVlJdMgYLoDJrsxAwMgcCE14nxt 使用Springfox Swagger生成API,并导入Postman,完成API单元测试 Swagger: 是一套API定义的规范,按照这套规范的要求去定义接口及接口相关信息,再通过可…

我的飞书:https://rvg7rs2jk1g.feishu.cn/docx/TVlJdMgYLoDJrsxAwMgcCE14nxt

使用Springfox Swagger生成API,并导入Postman,完成API单元测试

Swagger: 是一套API定义的规范,按照这套规范的要求去定义接口及接口相关信息,再通过可以解析这套规范工具,就可以生成各种格式的接口文档,以及在线接口调试页面,通过自动文档的方式,解决了接口文档更新不及时的问题。

Springfox: 是对Swagger规范解析并生成文档的一个实现。

代码配置

因为 Springfox 版本(3.0) 的问题,他的版本只有在 springBoot 2.5x能够进行使用,如果我们这里使用springBoot 2.7x及以上就会出现兼容性问题,此时我们就要进行一些适配操作

这里我使用的springBoot版本为 2.7.6

我们需要在 pom 文件中加入对应依赖

统一管理版本,在properties标签中加入版本号

<!-- springfox -->
<springfox-boot-starter.version>3.0.0</springfox-boot-starter.version>

引入依赖

<!-- API文档生成,基于swagger2 -->
<dependency><groupId>io.springfox</groupId><artifactId>springfox-boot-starter</artifactId><version>${springfox-boot-starter.version}</version>
</dependency>
<!-- SpringBoot健康监控(只是为了方便关注spring状态) -->
<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-actuator</artifactId>
</dependency>

编写配置类

将以下代码添加至项目中

import org.springframework.boot.actuate.autoconfigure.endpoint.web.CorsEndpointProperties;
import org.springframework.boot.actuate.autoconfigure.endpoint.web.WebEndpointProperties;
import org.springframework.boot.actuate.autoconfigure.web.server.ManagementPortType;
import org.springframework.boot.actuate.endpoint.ExposableEndpoint;
import org.springframework.boot.actuate.endpoint.web.*;
import org.springframework.boot.actuate.endpoint.web.annotation.ControllerEndpointsSupplier;
import org.springframework.boot.actuate.endpoint.web.annotation.ServletEndpointsSupplier;
import org.springframework.boot.actuate.endpoint.web.servlet.WebMvcEndpointHandlerMapping;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
import org.springframework.util.StringUtils;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.oas.annotations.EnableOpenApi;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;import java.util.ArrayList;
import java.util.Collection;
import java.util.List;// 配置类
@Configuration
// 开启Springfox-Swagger
@EnableOpenApi //生成 API 功能
public class SwaggerConfig {/*** Springfox-Swagger基本配置* @return*/@Beanpublic Docket createApi() {Docket docket = new Docket(DocumentationType.OAS_30).apiInfo(apiInfo()).select().apis(RequestHandlerSelectors.basePackage("com.example.forum.controller")) //填写自己项目中的controller包路径.paths(PathSelectors.any()).build();return docket;}// 配置API基本信息,以下信息都为自定义信息private ApiInfo apiInfo() {ApiInfo apiInfo = new ApiInfoBuilder().title("") //标题.description("") //描述.contact(new Contact("name", "url", "email")).version("1.0").build();return apiInfo;}/*** 解决SpringBoot 2.6.0以上与Swagger 3.0.0 不兼容的问题* 复制即可**/@Beanpublic WebMvcEndpointHandlerMapping webEndpointServletHandlerMapping(WebEndpointsSupplier webEndpointsSupplier,ServletEndpointsSupplier servletEndpointsSupplier,ControllerEndpointsSupplier controllerEndpointsSupplier,EndpointMediaTypes endpointMediaTypes, CorsEndpointProperties corsProperties,WebEndpointProperties webEndpointProperties, Environment environment) {List<ExposableEndpoint<?>> allEndpoints = new ArrayList();Collection<ExposableWebEndpoint> webEndpoints = webEndpointsSupplier.getEndpoints();allEndpoints.addAll(webEndpoints);allEndpoints.addAll(servletEndpointsSupplier.getEndpoints());allEndpoints.addAll(controllerEndpointsSupplier.getEndpoints());String basePath = webEndpointProperties.getBasePath();EndpointMapping endpointMapping = new EndpointMapping(basePath);boolean shouldRegisterLinksMapping = this.shouldRegisterLinksMapping(webEndpointProperties, environment,basePath);return new WebMvcEndpointHandlerMapping(endpointMapping, webEndpoints, endpointMediaTypes,corsProperties.toCorsConfiguration(), new EndpointLinksResolver(allEndpoints, basePath),shouldRegisterLinksMapping, null);}private boolean shouldRegisterLinksMapping(WebEndpointProperties webEndpointProperties, Environment environment,String basePath) {return webEndpointProperties.getDiscovery().isEnabled() && (StringUtils.hasText(basePath)|| ManagementPortType.get(environment).equals(ManagementPortType.DIFFERENT));}}

修改配置文件

在yml文件中加入新的配置,这里必须加入!!不然会出现不适配的问题,因为使用的SpringBoot相对于Springfox来说是高版本

spring:mvc:path match:matching-strategy: ant_path_matcher

API常用注解以及使用方法

@Api

作用在 Controller 上,对控制器类进行说明

tags = " 说明该类的作用,可以在前台界面上看到的注释 "

@ApiModel

作用在相应的类上,对返回响应数据的说明

@ApiModelProperty

作用在类的属性上,对属性的说明,也就是具体的对象上

@ApiOperation

作用在具体的方法上,对API接口的说明

@ApiParam

作用在方法中的每一个参数上,对参数的属性进行说明

访问API列表

启动程序,在浏览器中输入网址: http://127.0.0.1:项目端口号/swagger-ui/index.html

进入对应网页

连接 postman

获取 API 地址,获取API资源地址之后复制

打开 postman,选择要复制到的地方.选择 Woekspaces ,选择 My Workspace

在左边工具栏中找到 APIs ,选择 import ,输入刚才复制的网址

http://www.shuangfujiaoyu.com/news/25844.html

相关文章:

  • 北京海淀区网站建设深圳网
  • 蓝色管理系统网站模版网址大全2345
  • 网站3网合一是怎么做的亚马逊关键词
  • 从事电子商务的网站建设南宁网站建设优化服务
  • 网站建设基本流程规范福建百度代理公司
  • 17一起做网站后台找代写文章写手
  • 肇庆网站优化建设网络营销知识点
  • 淮南创业网成都网络优化公司有哪些
  • wordpress菜单参数设置seo网站编辑是做什么的
  • 海安网站开发郑州网站建设推广优化
  • 泉州网站制作推广轻松seo优化排名
  • 365房产网百度关键词优化工具
  • wordpress站点logo设置最新国内重大新闻
  • 免费行情软网站百度自媒体注册入口
  • 都匀经济开发区建设局网站好搜搜索引擎
  • 关于推进政府网站集约化建设的报告seo培训讲师招聘
  • 赚钱网站怎么做免费的网站域名查询
  • 成都网站开发scwbo已矣seo排名点击软件
  • 网站开发与设计的参考文献网站推广常用方法
  • 专业网站建设制作公司seo软件排行榜前十名
  • 地方门户类网站产品推广seo详细教程
  • 做网站多少钱 佛山太原优化排名推广
  • 做网站多少钱西宁君博专注同城推广
  • 个人网站怎么做银行卡支付宝java培训
  • 软件网站排名网络促销方案
  • 互联网公司岗位有哪些企业网站seo优化外包
  • 做时时彩网站平台免费入驻的电商平台
  • 快速做网站关键词排名公司网络推广方案
  • 接app推广接单平台需要优化的网站有哪些
  • 比较好的做网站公司人民日报今日头条新闻