跳转到主内容
极星编程网:以代码为星,赴技术山海!

想轻松生成接口文档?快来学学Swagger!

前言

各位编程老铁们,你们是不是也经常被接口文档折磨得头昏脑胀?前端抱怨后端没更新,后端又觉得写文档太麻烦。今天,我就来给大家介绍一个神器——Swagger,让你轻松生成接口文档,告别烦恼!

一、简介

Swagger 是一个规范且完整的框架,用于生成、描述、调用和可视化 RESTful 风格的 Web 服务。简单来说,它就是一个自动生成接口文档的工具,让你的接口文档不再手动编写,省时又省力。

二、基本使用

1. 导入相关依赖

<dependency>
    <groupId>io.springfox</groupId>
    <artifactId>springfox-spring-web</artifactId>
    <version>2.9.2</version>
</dependency>
<dependency>
    <groupId>io.springfox</groupId>
    <artifactId>springfox-swagger2</artifactId>
    <version>2.9.2</version>
</dependency>
<dependency>
    <groupId>io.springfox</groupId>
    <artifactId>springfox-swagger-ui</artifactId>
    <version>2.9.2</version>
</dependency>

2. 编写配置文件

在配置文件目录下,添加 Swagger 的配置文件 SwaggerConfig.java。

@Configuration
@EnableSwagger2
public class SwaggerConfig {
}

2.1 配置基本信息

使用 Docket 来配置 Swagger 的基本信息,包括标题、描述、版本等。

private ApiInfo apiInfo() {
    Contact contact = new Contact(
                            

相关文章