当前位置:网站首页>swagger文档配置
swagger文档配置
2022-07-03 08:06:00 【小朋友哈哈】
swagger:
swagger是一个规范和完整的框架,可以生成,描述,调用和可视化RESTful 风格的 Web 服务。
springboot整合swagger
添加依赖
有两种模式,一个是swagger-ui.html,一个是doc.html(按自己要求所取)
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.9.2</version>
</dependency>
<!--swagger-ui.html模式 -->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.9.2</version>
</dependency>
<!--doc.html模式 -->
<dependency>
<groupId>com.github.xiaoymin</groupId>
<artifactId>swagger-bootstrap-ui</artifactId>
<version>1.9.2</version>
</dependency>创建swagger配置类:
package com.yan.config;
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 // 告诉springboot需要加载这个配置类
@EnableSwagger2 // 启用swagger
public class SwaggerConfig {
@Bean
public Docket createRestApi() {
return new Docket(DocumentationType.SWAGGER_2)
.apiInfo(apiInfo())
// 通过select返回一个实例,用来控制哪些接口暴露给swagger来展示。
.select()
// 对所有api进行监控
.apis(RequestHandlerSelectors.any())
.paths(PathSelectors.any())
.build();
}
// 创建api的基本信息,(这些信息会展示在文档中,比如title描述之类的)
public ApiInfo apiInfo() {
return new ApiInfoBuilder()
.title("spring-web项目")
.description("对项目的描述").build();
}
}
验证:
项目启动之后,可以在访问localhost:8080/swagger-ui.html或者localhost:8080/doc.html来访问了。(根据自己依赖导入来选择)
一些注解:
Controller层
定义接口名称:@Api(tags="xxx")
定义方法名称:@ApiOperation(value="xxx")
定义param参数的各个属性:@ApiImplicitParam(name = "xx", value = "xx", paramType = "xx")
如: @ApiImplicitParam(name = "pid", value = "产品id", paramType = "String")
实体
定义对象名称:@ApiModel("xxx")
定义参数名称:@ApiModelProperty(value = "xxx")边栏推荐
- PHP common sorting algorithm
- [untitled]
- Docker installs MySQL and successfully uses Navicat connection
- Wpf: solve the problem that materialdesign:dialoghost cannot be closed
- Storage of data
- RM delete file
- What is BFC?
- About the problem that the editor and the white screen of the login interface cannot be found after the location of unityhub is changed
- Unity one click AssetBundle
- About Wireshark's unsuccessful installation of npcap
猜你喜欢

创业团队如何落地敏捷测试,提升质量效能?丨声网开发者创业讲堂 Vol.03

*p++、*++p、++*p、(*p)++

My touch screen production "brief history" 2

LwIP learning socket (application)

freetype库的移植

An article for you to understand - Manchester code
![[set theory] order relation (hastu example | divisive relation hastu | inclusive relation hastu | refinement relation hastu)](/img/de/1c75b5e7ed79aca47462de365428a7.jpg)
[set theory] order relation (hastu example | divisive relation hastu | inclusive relation hastu | refinement relation hastu)

C language learning notes (mind map)

JS common basic case sorting (continuous update)

About the problem that the editor and the white screen of the login interface cannot be found after the location of unityhub is changed
随机推荐
Viz artist advanced script video tutorial -- stringmap use and vertex operation
PHP common sorting algorithm
Pulitzer Prize in the field of information graphics - malofiej Award
How can entrepreneurial teams implement agile testing to improve quality and efficiency? Voice network developer entrepreneurship lecture Vol.03
C#课程设计之学生教务管理系统
the installer has encountered an unexpected error installing this package
L'installateur a été installé avec une erreur inattendue
一条通往服务器所有端口的隧道
【cocos creator】点击按钮切换界面
P2704 [NOI2001] 炮兵阵地(状压dp)
VMware virtual machine configuration static IP
Storage of data
Register keyword
What does (+) in Oracle mean
[step on the pit series] MySQL failed to modify the root password
Xlua task list youyou
About Wireshark's unsuccessful installation of npcap
idea取消引用显示效果
Microsoft Security Response Center
Unity2019_ Natural ambient light_ Sky box