当前位置:网站首页>Swagger配置与使用
Swagger配置与使用
2022-07-17 05:08:00 【qq_42042158】
1、导入两个依赖
<!-- swagger2 -->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.9.2</version>
</dependency>
<!-- Swagger第三方ui依赖 -->
<dependency>
<groupId>com.github.xiaoymin</groupId>
<artifactId>swagger-bootstrap-ui</artifactId>
<version>1.9.6</version>
</dependency>
Swaggeui推荐使用第三方的依赖
2、在项目中使用java配置类的方式配置swagger
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.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
@Configuration
@EnableSwagger2
public class SwaggerConfig {
/** * swagger公帮助我们生成按口文档 * 1:配置生成的文档信息 * 2:配置生成规则 */
/** * Docket封装接口文档信息 * */
@Bean
public Docket createRestApi(){
return new Docket(DocumentationType.SWAGGER_2) //指定文档风格
.apiInfo(apiInfo())
.select() //选择生成策略
.apis(RequestHandlerSelectors.basePackage("com.zstudyj.controller")) //选择要生成接口文档的类
.paths(PathSelectors.any())
.build();
}
/** * 指定生成的文档中的封面信息:文档标题、 版本、作者等 * @return ApiInfo */
private ApiInfo apiInfo(){
return new ApiInfoBuilder()
.title("xx商城接口文档") //添加标题
.description("xx商城接口文档") //添加描述
.contact(new Contact("zxj","http:localhost:8081/doc.html","[email protected]"))
.version("v 2.0.1")
.build();
}
}
配置完成 ,访问接口 http://ip:port/doc.html
3、Swagger注解说明
swagger提供了一套注解, 可以对每个接口进行详细说明
@Api类注解,在控制器类添加此注解,可以对控制器类进行功能说明
效果

@ApiOperation方法注解,在方法上添加此注解,可以对方法进行功能说明

效果
@ApiImplicitParams和@ApiImplicitParam参数注解,说明参数的类型,名称,是否必须,默认值等

效果
@ApiModel和@ApiModelProperty当接口参数和返回值为对象类型时,在实体类中添加注解说明

边栏推荐
- es6新增-数组部分
- 路由器loopback口实验
- Bi design: distributed high concurrency epidemic prevention health management system based on vue+socket+redis
- 单臂路由配置
- Use echars to realize water drop, ring, segmentation, stacking, organization chart, map outline and other charts
- 【C语言—零基础_学习_复习_第五课】基本运算符的运算性质
- 学习C语言第三天
- 网络命令:网卡信息,netstat,arp
- 运维安全要了解的二三事
- 【AI】利用简单神经网络做动作识别——基于coco关键点
猜你喜欢

Use echars to realize water drop, ring, segmentation, stacking, organization chart, map outline and other charts

Applet cloud development form submission and data acquisition in the page

es6新增-数组部分

【C语言_复习_学习第二课】什么是进制?进制之间应该如何转换

es6新增-数组/对象的解构赋值

IText modify PDF Text

BUUCTF 杂项——二维码

CityEngine 三维管道建模教程

手把手教你复现Log4j2核弹级漏洞

uniapp中使用ucharts图表,饼状图,柱状图,折线图
随机推荐
获取数组中对象内部的数值最大与最小值多功能版及点名系统完整版并展示效果
基于PaddleOCR解决文本检测训练模型与inference模型预测效果不一致的问题
路由器loopback口实验
Ucharts chart, pie chart, bar chart and line chart are used in uniapp
STL容器——set集合的应用
网络命令:网卡信息,netstat,arp
数据可视化
Class object automatic injection attribute operation tool
【C语言—零基础第七课】顺序结构与选择结构
【LeetCode——编程能力入门第一天】基本数据类型[在区间范围内统计奇数数目/去掉最低工资和最高工资后的工资平均值)
RK356x U-Boot研究所(命令篇)3.4 mem内存相关命令的用法
645. 错误的集合
Cesium 获取鼠标点击处经纬度的三种方法
学习C语言第三天
es6新增-对象部分
markdown笔记以及Typora相关快捷键
JS native object plus attributes
【Es6】利用添加数据,筛选并传输至页面等多项功能实现案例
Excel计算本月剩余天数
Cesium geojson数据的添加与移除