您好,欢迎来到华佗小知识。
搜索
您的当前位置:首页Swagger 学习笔记

Swagger 学习笔记

来源:华佗小知识

背景

首先指定schema[计划的提纲],实时更新最新API,降低集成风险;
早些年:制定word计划文档;
前后端分离:
   前端测试后端接口:postman
   后端提供接口,需要实时更新最新的消息改动

什么是swagger

号称世界上最流行的Api框架;
Restful   Api  文档在线自动生成工具 => Api 文档与Api 定义同步更新
直接运行,可以在线测试API接口
支持多种语言

官网:

swagger2+ui

 

使用swagger

springboot集成swagger

 1.新建一个springboot web 项目

 2.导入相关依赖

<!-- https://mvnrepository.com/artifact/io.springfox/springfox-swagger-ui -->
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger-ui</artifactId>
            <version>2.9.2</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/io.springfox/springfox-swagger2 -->
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger2</artifactId>
            <version>2.9.2</version>
        </dependency>

3.编写一个Hello工程

4.配置Swagger

package com.mikey.swagger_demo.config;

import org.springframework.context.annotation.Configuration;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * @ProjectName swagger_demo
 * @Author 麦奇
 * @Email biaogejiushibiao@outlook.com
 * @Date 9/5/19 9:25 AM
 * @Version 1.0
 * @Description:
 **/
@Configuration
@EnableSwagger2 //开启swagger
public class SwaggerConfig {
    
}

5.测试页面

http://localhost:8080/swagger-ui.html 

 

配置Swagger的bean实例

 

 

 

配置Swagger扫描接口

Docket.select()

配置Api文档的分组

 

 

 

 

 

 

 

参考相关博客:

转载于:https://www.cnblogs.com/biaogejiushibiao/p/11456155.html

因篇幅问题不能全部显示,请点此查看更多更全内容

Copyright © 2019- huatuo0.cn 版权所有 湘ICP备2023017654号-2

违法及侵权请联系:TEL:199 18 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务