美文网首页
Swagger2的使用简单描述

Swagger2的使用简单描述

作者: 西谷haul | 来源:发表于2021-11-02 11:30 被阅读0次

1、pom中添加依赖:

<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
</dependency>

2、添加swagger配置

/**
 * Swagger2配置信息
 */
@Configuration
@EnableSwagger2
public class Swagger2Config {
    @Bean
    public Docket webApiConfig(){
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("webApi")
                .apiInfo(webApiInfo())
                .select()
                //只显示api路径下的页面
                .paths(Predicates.and(PathSelectors.regex("/api/.*")))
                .build();
    }

    @Bean
    public Docket adminApiConfig(){
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("adminApi")
                .apiInfo(adminApiInfo())
                .select()
                //只显示admin路径下的页面
                .paths(Predicates.and(PathSelectors.regex("/admin/.*")))
                .build();
    }

    private ApiInfo webApiInfo(){
        return new ApiInfoBuilder()
                .title("网站-API文档")
                .description("本文档描述了网站微服务接口定义")
                .version("1.0")
                .contact(new Contact("atguigu", "http://atguigu.com", "493211102@qq.com"))
                .build();
    }

    private ApiInfo adminApiInfo(){
        return new ApiInfoBuilder()
                .title("后台管理系统-API文档")
                .description("本文档描述了后台管理系统微服务接口定义")
                .version("1.0")
                .contact(new Contact("atguigu", "http://atguigu.com", "49321112@qq.com"))
                .build();
    }
}

3、什么是swagger2

编写和维护接口文档是每个程序员的职责,根据Swagger2可以快速帮助我们编写最新的API接口文档,再也不用担心开会前仍忙于整理各种资料了,间接提升了团队开发的沟通效率。
常用注解
swagger通过注解表明该接口会生成文档,包括接口名、请求方法、参数、返回信息的等等。
@Api:修饰整个类,描述Controller的作用
@ApiOperation:描述一个类的一个方法,或者说一个接口
@ApiParam:单个参数描述
@ApiModel:用对象来接收参数
@ApiModelProperty:用对象接收参数时,描述对象的一个字段
@ApiImplicitParam:一个请求参数
@ApiImplicitParams:多个请求参数

相关文章

  • Swagger2的使用简单描述

    1、pom中添加依赖: 2、添加swagger配置 3、什么是swagger2 编写和维护接口文档是每个程序员的职...

  • Swagger2 Zuul 整合

    Swagger2 Swagger2是一个RESTful接口进行描述和展示的工具,可以通过 springfox-sw...

  • Swagger注释使用问题

    在Spring Boot中使用Swagger2构建RESTful API时常常需要对API进行文字性描述其中要用到...

  • Swagger2的实战

    一、Swagger2的官方文档 Swagger官方地址 二、Swagger2的相关注解的介绍 1、接口相关的描述 ...

  • Swagger2创建接口文档

    Spring Boot整合Swagger2 swagger2 是一个规范和完整的框架,用于生成、描述、调用和可视化...

  • swagger2笔记

    swagger2搭建 引入 配置 描述类 描述接口 https://blog.csdn.net/liuchuanh...

  • 整合swagger2

    swagger2详解 [toc] 为啥使用swagger2 由于接口众多,调用者不懂如何使用接口参数,并且接口逻辑...

  • springboot整合swagger2

    发现我们公司蛮喜欢用swagger2的,那就学习一波 swagger2是什么 简单来说,swagger2通过注解可...

  • 在 Spring Boot 项目中使用 Swagger2 构建

    在 pom.xml 中添加 Swagger2 的相关依赖: 创建 Swagger2 配置类: 使用 @ApiOpe...

  • Spring Boot 使用swagger2

    Spring Boot 使用swagger2 swagger2可以减少我们的编写文档工作,尤其现在是前后端分离。后...

网友评论

      本文标题:Swagger2的使用简单描述

      本文链接:https://www.haomeiwen.com/subject/xgexzltx.html