首页 技术 正文
技术 2022年11月18日
0 收藏 507 点赞 3,268 浏览 1988 个字

在正式进入主题之前,先说说实际工作中遇到的问题。不算是传统的原生APP开发,还是眼下的H5混合开发,只要是需要前后端通过接口配合的,往往都存在几个普遍的问题

(1)接口文档谁来写,尤其是跨部门,并且,前后端开发人员忙闲不一致时,很难安排;

(2)开发中,接口数据变动了,而接口文档更新不及时,后面项目交接时,那就会一塌糊涂(如果基于看代码的话,那就要看相关人员有没有空了);

(3)用什么写也是个麻烦事,word?markdown?专门的接口系统?而且多人协作开发接口时,同步是个极其麻烦的事;

看过上面的问题,可见一个“规范的、可实时更新的”接口文档是多么的重要。这一篇里面,我们要说的就是把接口文档集成到工程里面,让写接口的人员负责维护接口文档。好了,正式步入正题;

一、第三方选型

这里不多说,我们选择的就是swagger,其他类似的产品还有很多,自行百度。

二、添加依赖

<!-- swagger2 API接口文档,自动生成 -->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.8.0</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.8.0</version>
</dependency>
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.3.0</version>
</dependency>

  

三、swagger配置文件

接口开发-集成接口文档(swagger)

package com.univalsoft.springbootapimaster.common.configuration;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.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;@Configuration
@EnableSwagger2
public class SwaggerConfig { @Bean
public Docket createRestApi() {
return new Docket(DocumentationType.SWAGGER_2)
.apiInfo(apiInfo())
.select()
.apis(RequestHandlerSelectors.basePackage("com.univalsoft.springbootapimaster.api.controller"))
.paths(PathSelectors.any())
.build();
} private ApiInfo apiInfo() {
return new ApiInfoBuilder()
.title("环球软件 API 接口文档")
.description("具体项目名称,维护人")
// .termsOfServiceUrl("http://www.by-health.com/")
//.contact(contact)
.version("1.0")
.build();
}}

  

四、给Controller添加注解

接口开发-集成接口文档(swagger)

五、运行系统,浏览器中输入 http://localhost:8080/swagger-ui.html

接口开发-集成接口文档(swagger)

接口文档已经集成好了,后面更多的工作,需要接口开发人员认真负责,及时维护。这些与技术无关,看的更多的是一个人的耐心、责任心。

多说一句,“技术的高低只是暂时的,人品确是一辈子的”。

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:8,991
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,505
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,349
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,134
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,766
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,844