Swagger

背景

在前后端分离开发的时代,前端和后端的实时交互(后端接口改变前端可以及时看到),成为了一个主要问题之一,前后端沟通成本越来越高,前后端人员无法做到“即时协商”,最终导致问题爆发

以前的解决方案:

  • 指定schema【计划提纲】,实时更新最新的API,降低集成的风险
  • 制定word计划文档
  • 前后端分离:
    • 前端测试后端接口,工具:postman
    • 后端提供接口,需要实时更新最新的消息及改动

简介

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

官网:https://swagger.io/


SpringBoot集成Swagger

需要的两个依赖:

在这里插入图片描述

新建一个SpringBoot-Web项目,并导入相关依赖

<dependencies>
        <!-- https://mvnrepository.com/artifact/io.springfox/springfox-swagger2 -->
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger2</artifactId>
            <version>2.9.2</version>
        </dependency>
        <!-- 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>

编写一个Hello工程

/**
 * @Author 凉白开_LBK
 * @Date 2021/10/25 10:08
 * @Explain
 */
@RestController
public class HelloController {
   
   
    @RequestMapping("/HelloWorld")
    public String hello(){
   
   
        return "hello,world";
    }
}

配置SwaggerConfig

在这里插入图片描述

测试运行:http://localhost:8080/swagger-ui.html

在这里插入图片描述

配置Swagger

package com.lbk.swagger.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

LBK.

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值