当前位置:网站首页>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")
边栏推荐
- Huawei s5700 switch initialization and configuration SSH and telnet remote login methods
- Lua hot update basic grammar
- Iterm2 setting
- 超限黑客认知
- Generate video using clipout in viz engine
- [untitled]
- How can entrepreneurial teams implement agile testing to improve quality and efficiency? Voice network developer entrepreneurship lecture Vol.03
- Basic operation and process control
- 一条通往服务器所有端口的隧道
- the installer has encountered an unexpected error installing this package
猜你喜欢
超限黑客认知
VMware virtual machine configuration static IP
Puhua PLM empowers the whole scene product lifecycle management and helps the enterprise digital transformation of the main line of products
About the problem that the editor and the white screen of the login interface cannot be found after the location of unityhub is changed
Xlua task list youyou
Youyou1 of xlua knapsack system
My touch screen production "brief history" 1
About Wireshark's unsuccessful installation of npcap
Getting started with minicom
Unity change default editor
随机推荐
Pycharm remote ssh pyenv error: pydev debugger: warning: trying to add breakpoint to file that does
Ventuz Foundation Series "one step at the door"
Yolo series --- xml2txt script
Client server model
regular expression
C#课程设计之学生教务管理系统
VMware virtual machine configuration static IP
What is a data type? What is the use of data types?
Golang json格式和结构体相互转换
Huawei s5700 switch initialization and configuration SSH and telnet remote login methods
Quelle est la définition? Qu'est - ce qu'une déclaration? Quelle est la différence?
Idea unreference Display Effect
go 解析身份证
Demonstration of plug-in use of ventuz basic series
Huawei s5700 switch initialization and configuration Telnet, SSH user methods
*p++、*++p、++*p、(*p)++
oracle 插入单引号
haproxy+keepalived搭建01
Golang 中string和int类型相互转换
Register keyword