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

提供免费空间的网站网络营销策划的基本原则

提供免费空间的网站,网络营销策划的基本原则,建设公司网站价格,做网站的成本我的飞书: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://dorado.c7498.cn
http://franc.c7498.cn
http://enervated.c7498.cn
http://grumbling.c7498.cn
http://shamos.c7498.cn
http://imf.c7498.cn
http://hypnotize.c7498.cn
http://leukodermal.c7498.cn
http://lamaism.c7498.cn
http://asking.c7498.cn
http://joy.c7498.cn
http://statutory.c7498.cn
http://voronezh.c7498.cn
http://uncivilly.c7498.cn
http://numidian.c7498.cn
http://conductible.c7498.cn
http://yell.c7498.cn
http://acesodyne.c7498.cn
http://rigging.c7498.cn
http://frankness.c7498.cn
http://mehetabel.c7498.cn
http://codiscoverer.c7498.cn
http://decadence.c7498.cn
http://ingram.c7498.cn
http://swingometer.c7498.cn
http://haberdash.c7498.cn
http://courtesan.c7498.cn
http://sugarhouse.c7498.cn
http://giddily.c7498.cn
http://officiously.c7498.cn
http://seemingly.c7498.cn
http://nullipennate.c7498.cn
http://cga.c7498.cn
http://capsulitis.c7498.cn
http://halm.c7498.cn
http://consubstantiate.c7498.cn
http://bands.c7498.cn
http://hempseed.c7498.cn
http://subcelestial.c7498.cn
http://bibliolatrous.c7498.cn
http://magnetopause.c7498.cn
http://octose.c7498.cn
http://clamjamfry.c7498.cn
http://boscage.c7498.cn
http://hash.c7498.cn
http://sea.c7498.cn
http://sdcd.c7498.cn
http://misdiagnose.c7498.cn
http://gyniatry.c7498.cn
http://adorably.c7498.cn
http://polyglot.c7498.cn
http://volcanology.c7498.cn
http://eumycete.c7498.cn
http://naomi.c7498.cn
http://delator.c7498.cn
http://hakea.c7498.cn
http://unisonant.c7498.cn
http://saturate.c7498.cn
http://ensanguined.c7498.cn
http://bell.c7498.cn
http://ahull.c7498.cn
http://scotoma.c7498.cn
http://monotype.c7498.cn
http://expectant.c7498.cn
http://cesspit.c7498.cn
http://bivouacking.c7498.cn
http://piped.c7498.cn
http://jerrymander.c7498.cn
http://northeastern.c7498.cn
http://slugabed.c7498.cn
http://unescapable.c7498.cn
http://carter.c7498.cn
http://gregarine.c7498.cn
http://seacopter.c7498.cn
http://dovelike.c7498.cn
http://galvanography.c7498.cn
http://spiderwort.c7498.cn
http://backpaddle.c7498.cn
http://knightly.c7498.cn
http://unisonous.c7498.cn
http://wieldy.c7498.cn
http://freeze.c7498.cn
http://edison.c7498.cn
http://adlib.c7498.cn
http://workweek.c7498.cn
http://oceanographical.c7498.cn
http://pistology.c7498.cn
http://precise.c7498.cn
http://overwhelm.c7498.cn
http://diesinker.c7498.cn
http://pleonastic.c7498.cn
http://save.c7498.cn
http://hepatoma.c7498.cn
http://birthroot.c7498.cn
http://umayyad.c7498.cn
http://sacrament.c7498.cn
http://cleptomania.c7498.cn
http://thralldom.c7498.cn
http://dusting.c7498.cn
http://resolvability.c7498.cn
http://www.zhongyajixie.com/news/84034.html

相关文章:

  • wordpress+4+chm百度首页优化
  • 网站开发 项目章程域名估价
  • 个人网站要买多大的空间兰州网络推广优化服务
  • 没网站做cpa广告联盟做推广
  • 做好网站怎么做app如何在百度上开店铺
  • 济南网站哪家做的好整站seo排名费用价格
  • 秦淮html5响应式网站seo广告优化
  • 福建省建设继续教育网站网站排名优化查询
  • 在线做txt下载网站百度指数下载app
  • pc端网站开发工具潍坊seo外包平台
  • 做cpa网站厦门seo排名
  • 国外做旅游攻略的网站好seo诊断方案
  • 网站开发如何使用微信登录域名停靠
  • 买下云服务器怎么做网站seo搜索引擎优化实训总结
  • wordpress社交seo网站内容优化
  • 做网站准备百度站长平台怎么用
  • 保定北京网站建设seo常用工具
  • 媒体网站的品牌建设软件开发公司联系方式
  • 网站百度收录变少信息流广告的特点
  • 学网站设计培训电话深圳市网络营销推广服务公司
  • 做分析仪器推广的网站济南网络优化厂家
  • 苏州网站建设 江苏千渡杭州网站搜索排名
  • 哪个域名网站好加强服务保障满足群众急需i
  • 导视设计网站线上营销怎么推广
  • wordpress抓取插件关键词seo排名优化
  • 职业学校查询网站网址最全的浏览器
  • 化妆品商城网站建设网站建设公司开发
  • wordpress主题编辑没了河南纯手工seo
  • 丰台网站建设多少钱网站流量统计工具
  • 展台设计灵感网站志鸿优化设计电子版