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

网站建设案例代理商/seo网络营销是什么意思

网站建设案例代理商,seo网络营销是什么意思,中文 域名的网站,手机网站jquery底部导航菜单一、使用介绍 什么是 Swagger? Swagger™的目标是为REST APIs 定义一个标准的,与语言无关的接口,使人和计算机在看不到源码或者看不到文档或者不能通过网络流量检测的情况下能发现和理解各种服务的功能。当服务通过Swagger定义,消费者就能与…

一、使用介绍

什么是 Swagger?

Swagger™的目标是为REST APIs 定义一个标准的,与语言无关的接口,使人和计算机在看不到源码或者看不到文档或者不能通过网络流量检测的情况下能发现和理解各种服务的功能。当服务通过Swagger定义,消费者就能与远程的服务互动通过少量的实现逻辑。类似于低级编程接口,Swagger去掉了调用服务时的很多猜测。 
浏览 Swagger-Spec 去了解更多关于Swagger 项目的信息,包括附加的支持其他语言的库。

如何集成Swagger-springmvc到我们的项目中?

依赖:

Maven
<dependency>
<groupId>com.mangofactory</groupId>
<artifactId>swagger-springmvc</artifactId>
<version>0.9.4</version>
</dependency>
Gradle
repositories {
jcenter()
}compile "com.mangofactory:swagger-springmvc:0.9.4"

使用:

要最快捷地启动swagger-springmvc项目并且使用默认设置,推荐的方式是使用SwaggerSpringMvc插件

Spring Java Configuration

@Configuration
@EnableWebMvc
@EnableSwagger
@ComponentScan("com.myapp.packages")
public class WebAppConfig {...
}

Spring xml Configuration

<mvc:annotation-driven/> <!-- Required so swagger-springmvc can access spring's RequestMappingHandlerMapping  -->
<bean class="com.mangofactory.swagger.configuration.SpringSwaggerConfig" />

SwaggerSpringMvcPlugin XML Configuration

为了使用这个插件,你需要创造一个spring Java配置类。使用spring的 @Configuration ,这个配置类必须被定义到你的xml上下文

<!-- Required so swagger-springmvc can access spring's RequestMappingHandlerMapping  -->
<mvc:annotation-driven/>


<bean class="com.yourapp.configuration.MySwaggerConfig"/>
@Configuration
@EnableSwagger //Loads the spring beans required by the framework
public class MySwaggerConfig {private SpringSwaggerConfig springSwaggerConfig;/**
* Required to autowire SpringSwaggerConfig
*/
@Autowired
public void setSpringSwaggerConfig(SpringSwaggerConfig springSwaggerConfig) {this.springSwaggerConfig = springSwaggerConfig;
}/**
* Every SwaggerSpringMvcPlugin bean is picked up by the swagger-mvc framework - allowing for multiple
* swagger groups i.e. same code base multiple swagger resource listings.*/
@Bean
public SwaggerSpringMvcPlugin customImplementation(){return new SwaggerSpringMvcPlugin(this.springSwaggerConfig).includePatterns(".*pet.*");
}}

SwaggerSpringMvcPlugin Spring Java Configuration

使用@EnableSwagger注解 
自动注入SpringSwaggerConfig 
定义一个或多个SwaggerSpringMvcPlugin实例,通过springs @Bean注解

@Configuration
@EnableWebMvc
@EnableSwagger
@ComponentScan("com.myapp.controllers")
public class CustomJavaPluginConfig {private SpringSwaggerConfig springSwaggerConfig;@Autowired
public void setSpringSwaggerConfig(SpringSwaggerConfig springSwaggerConfig) {this.springSwaggerConfig = springSwaggerConfig;
}@Bean //Don't forget the @Bean annotation
public SwaggerSpringMvcPlugin customImplementation(){return new SwaggerSpringMvcPlugin(this.springSwaggerConfig).apiInfo(apiInfo()).includePatterns(".*pet.*");
}private ApiInfo apiInfo() {ApiInfo apiInfo = new ApiInfo("My Apps API Title","My Apps API Description","My Apps API terms of service","My Apps API Contact Email","My Apps API Licence Type","My Apps API License URL");return apiInfo;
}
}

二、碰到的问题

关于@API注解

在Swagger Annotation中: 

API表示一个开放的API,可以通过description简要描述该API的功能。 
在一个@API下,可有多个@ApiOperation,表示针对该API的CRUD操作。在ApiOperation Annotation中可以通过value,notes描述该操作的作用,response描述正常情况下该请求的返回对象类型。 
在一个ApiOperation下,可以通过ApiResponses描述该API操作可能出现的异常情况。 

ApiParam用于描述该API操作接受的参数类型

再接着,为项目的Model对象添加Swagger Annotation,这样Swagger Scanner可以获取更多关于Model对象的信息。

@ApiModel(value = "A SayingRepresentation is a representation of greeting")
@JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL)
public class SayingRepresentation {
private long id;
@ApiModelProperty(value = "greeting content", required = true)
private String content;public SayingRepresentation(long id, String content) {this.id = id;this.content = content;
}public long getId() {return id;
}public String getContent() {return content;
}

通过上面的步骤,项目已经具备了提供Swagger格式的API信息的能力,接下来,我们把这些信息和Swagger UI集成,以非常美观,实用的方式把这些API信息展示出来。

和Swagger UI的集成

首先,从github(https://github.com/wordnik/swagger-ui)上下载Swagger-UI, 把该项目dist目录下的内容拷贝到项目的resources的目录assets下。


然后,修改index.html, 把Swagger UI对象中的URL替换为自己的API路径。

  window.swaggerUi = new SwaggerUi({url: "/api/api-docs",dom_id: "swagger-ui-container",

最后,为了能访问到该页面,还需要在Service的Initialize方法中,添加AssetsBundle

public void initialize(Bootstrap<HelloWorldConfiguration> bootstrap) {//指定配置文件的名字bootstrap.setName("helloWorld");bootstrap.addBundle(new AssetsBundle("/assets", "/", "index.html"));
}

最后的效果图: 



三、评价

Swagger可以充当前后端交流的重要桥梁,方便快捷。很实用。

Swagger项目允许你生产,显示和消费你自己的RESTful服务。不需要代理和第三方服务。是一个依赖自由的资源集合,它能通过Swagger API动态的生成漂亮的文档和沙盒,因为Swagger UI没有依赖,你可以把他部署到任何服务器环境或者是你自己的机器。

四、参考资料

官网:http://swagger.io/

GitHub:

swagger-springmvc:https://github.com/martypitt/swagger-springmvc

swagger-ui:https://github.com/swagger-api/swagger-ui

swagger-core:https://github.com/swagger-api/swagger-core

swagger-spec:https://github.com/swagger-api/swagger-spec

http://www.lbrq.cn/news/122869.html

相关文章:

  • 网站的倒计时怎么做的/武汉久都seo
  • 长沙网站建设服务公司/黑帽seo
  • 乡镇网站个人做可以不/小说网站排名人气
  • 北京网站建设有哪些/企业查询
  • 静态网站案例/沧州网络推广外包公司
  • 青浦企业网站制作/论坛推广怎么做
  • 山东泰润建设集团网站/互联网营销师证书含金量
  • wap网站制作怎么做/邯郸seo优化公司
  • 做市场调查分析的网站/淘宝数据分析
  • 厦门网盛网站开发/网络营销推广方案
  • 网页网站开发平台/常州seo招聘
  • 如何建网站做传奇网友/凡科网站官网
  • 招聘网站分析如何做/seo优化工程师
  • 新手怎么引流推广/优化seo报价
  • 兰州做网站的公司有哪些/在线生成个人网站app
  • 深圳专业网站建设价格/太仓网站制作
  • 做网站公司排行/网页优化方法
  • 网站建设交流/百度收录链接提交入口
  • 百度开放云做网站/今日的新闻头条10条
  • 做网站 (公司)/给公司建网站需要多少钱
  • wordpress 主题 puma/公司排名seo
  • 定制网站建设济南/制作网站的基本步骤
  • 网站建设的准备工作/免费模板网站
  • 佛山网站建设找哪家/网站seo最新优化方法
  • 成都青羊网站建设/百度竞价推广流程
  • thinkphp做的商城网站分销平台/自己个人怎样做电商
  • 免费的毕业设计网站建设/登录注册入口
  • 吉林省四平市网站建设/网站页面分析作业
  • 网站建设需要些什么设备/百度退推广费是真的吗
  • 广东省建设安全卡查询网站/竞价恶意点击立案标准
  • 深度学习 Pytorch图像分类步骤
  • 2025开放原子开源生态大会 | openKylin的技术跃迁和全球协作
  • 测试tcpdump,分析tcp协议
  • C语言:20250714笔记
  • 如何将 iPhone 备份到云端:完整指南
  • [Linux 入门] Linux 引导过程、系统管理与故障处理全解析