当前位置:网站首页>How to form standard interface documents
How to form standard interface documents
2022-07-05 20:22:00 【Mountain King in kindergarten】
One 、 demand
When the front and rear ends are butted , The backend needs to provide a standard , In other words, it is very important for the front end to understand the interface documents . How to use annotations quickly 、 Simply form interface documents .
Two 、Swagger2 Switch knife4j Use
1、 stay pom.xml add knife4j Related dependence of
<!-- Integrate Knife4j-->
<dependency>
<groupId>com.github.xiaoymin</groupId>
<artifactId>knife4j-spring-boot-starter</artifactId>
<version>2.0.4</version>
</dependency>2、 stay Swagger2Config Add one @EnableKnife4j annotation , This annotation can open knife4j Enhancements for
@Configuration
@EnableSwagger2
@EnableKnife4j
public class Swagger2Config {
@Bean
public Docket ssoFront() {
return new Docket(DocumentationType.SWAGGER_2)
.apiInfo(apiInfo())
.select()
.apis(RequestHandlerSelectors.basePackage(" Package path of the interface "))
.paths(PathSelectors.any())
.build().groupName(" Group name ");
}
@Bean
public Docket ssoAdmin() {
return new Docket(DocumentationType.SWAGGER_2)
.apiInfo(apiInfo())
.select()
.apis(RequestHandlerSelectors.basePackage("com.user.controller.admin"))
.paths(PathSelectors.any())
.build().groupName("sso-admin");
}
@Bean
public Docket member() {
return new Docket(DocumentationType.SWAGGER_2)
.apiInfo(apiInfo())
.select()
.apis(RequestHandlerSelectors.basePackage("com.user.controller.member"))
.paths(PathSelectors.any())
.build().groupName("member-service");
}
@Bean
public Docket system() {
return new Docket(DocumentationType.SWAGGER_2)
.apiInfo(apiInfo())
.select()
.apis(RequestHandlerSelectors.basePackage("com.user.controller.system"))
.paths(PathSelectors.any())
.build().groupName("system-service");
}
private ApiInfo apiInfo() {
return new ApiInfoBuilder()
.title(" Module documentation ")
.description(" User module API file ")
.contact(new Contact(" author ", null, null))
.version("v1")
.build();
}
}3、 Run our SpringBoot application , visit API The document address can be viewed :http://localhost: Port number /doc.html
3、 ... and 、 Functional characteristics
contrast swagger Come on
1、 The returned result set supports folding , Convenient view
2、 The request parameters are JSON Check function
3、 knife4j Support the export of offline documents , Easy to send to others , Support Markdown Format ; Direct selection Document management -> Offline documents function , And then choose download Markdown that will do
3、 ... and 、 Use different annotations to form interface documents according to different request methods
One 、swagger Annotation application
1、 In the control layer , Can be in controller Use notes on @Api(tags = " Interface service name ") Mark the function of this controller .


2、 Annotations can be used on specific interfaces @ApiOperation(value = " Mailbox fuzzy matching query service interface ",notes = " Fuzzy matching of mailboxes ") Name the interface and describe the functions of the interface


Two 、@ApiOperation And Get Request annotations to use with
1、 Using annotations @RequestParam(value = " Incoming email ",required = false), Be careful name and value Can't coexist , Otherwise, the interface document cannot be generated .swagger It will automatically recognize this annotation and generate the corresponding document

Get The request data type is :
2、 Use @PathVariable(value = " Incoming email ",required = false) It's the same thing . The only difference is that the request type is different query, One is path

3、 Unwanted @ApiImplicitParam(name = " Mailbox fuzzy matching query ", value = "likeEmail", required = false) This annotation , Otherwise, two same parameters will appear .

3、 ... and 、@ApiOperation And Post Request annotations to use with
1、 Use @RequestBody Annotation request parameter entity . In the entity, add
@ApiModel(value = " XX request message ",description = " XX request message , The parent class is ",parent = class .class)2、 Add
@ApiModelProperty(value=" So and so attribute ",required = true)
@ApiOperation(" XX request message ")
@PostMapping("edit")
public JsonResult edit(@RequestBody EditDTO dto) {
return
}
swagger It will automatically scan the annotated data in the entity class to form the interface document
3、post Request data format ![]()
Four 、 All return messages with return parameters need to specify the return parameters

Only with a clear return message , And in the message Class name @ApiModel And attribute @ApiModelProperty Notes are also used , Then the data type of the returned message will also appear in the interface document .


Corresponding examples will also appear below 、
notes : For the combination of annotations and request types, please refer to the following article
POST、GET、@RequestBody and @RequestParam difference _Archie_java The blog of -CSDN Blog
边栏推荐
- Minimum commission for stock trading account opening, where to open an account with low commission? Is it safe to open an account on your mobile phone
- Leetcode skimming: binary tree 17 (construct binary tree from middle order and post order traversal sequence)
- E. Singhal and Numbers(质因数分解)
- 实操演示:产研团队如何高效构建需求工作流?
- Unity编辑器扩展 UI控件篇
- Go language | 01 wsl+vscode environment construction pit avoidance Guide
- [quick start of Digital IC Verification] 3. Introduction to the whole process of Digital IC Design
- 【数字IC验证快速入门】8、数字IC中的典型电路及其对应的Verilog描述方法
- c语言oj得pe,ACM入门之OJ~
- Leetcode skimming: binary tree 10 (number of nodes of a complete binary tree)
猜你喜欢

Leetcode: binary tree 15 (find the value in the lower left corner of the tree)

.Net分布式事务及落地解决方案

Leetcode brush questions: binary tree 11 (balanced binary tree)
![[quick start of Digital IC Verification] 1. Talk about Digital IC Verification, understand the contents of the column, and clarify the learning objectives](/img/90/88a1f79a07016738d2688548e21949.png)
[quick start of Digital IC Verification] 1. Talk about Digital IC Verification, understand the contents of the column, and clarify the learning objectives

Go language | 01 wsl+vscode environment construction pit avoidance Guide

【愚公系列】2022年7月 Go教学课程 004-Go代码注释

Oracle-表空间管理

14、Transformer--VIT TNT BETR
![[quick start of Digital IC Verification] 3. Introduction to the whole process of Digital IC Design](/img/92/7af0db21b3d7892bdc5dce50ca332e.png)
[quick start of Digital IC Verification] 3. Introduction to the whole process of Digital IC Design

How to select the Block Editor? Impression notes verse, notation, flowus
随机推荐
Leetcode brush question: binary tree 13 (the same tree)
mongodb文档间关系
Hong Kong stocks will welcome the "best ten yuan store". Can famous creative products break through through the IPO?
[quick start of Digital IC Verification] 3. Introduction to the whole process of Digital IC Design
【数字IC验证快速入门】6、Questasim 快速上手使用(以全加器设计与验证为例)
14、Transformer--VIT TNT BETR
【数字IC验证快速入门】8、数字IC中的典型电路及其对应的Verilog描述方法
Is it safe for CICC fortune to open an account online?
JS implementation prohibits web page zooming (ctrl+ mouse, +, - zooming effective pro test)
Reinforcement learning - learning notes 4 | actor critical
关于BRAM IP复位的优先级
小程序全局配置
ByteDance dev better technology salon was successfully held, and we joined hands with Huatai to share our experience in improving the efficiency of web research and development
信息学奥赛一本通 1337:【例3-2】单词查找树 | 洛谷 P5755 [NOI2000] 单词查找树
1、强化学习基础知识点
鸿蒙系统控制LED的实现方法之经典
Informatics Olympiad 1340: [example 3-5] extended binary tree
PyTorch 1.12发布,正式支持苹果M1芯片GPU加速,修复众多Bug
Leetcode brush questions: binary tree 11 (balanced binary tree)
mongodb基操的练习