swagger重启_简单了解一下 Swagger

一、Swagger

1、什么是 Swagger ?

Swagger 是一个规范和完整的框架,用于生成、描述、调用以及可视化的 Restful 风格的 Web 服务。

简单的理解:是一款 REST API 文档生成工具,生成在线的接口文档,方便接口测试。

2、为什么使用 Swagger?

前后端分离开发时,为了方便前后端接口调用规范,需要提供一个接口文档,但是维护这个接口文档是一个及其繁琐的事情,可能一不小心就忘记更新该文档从而导致前后端接口调用失败。

Swagger 就是为了解决这个问题而出现的(在线接口文档),其在接口方法上定义注解,并根据注解形成一个 html 页面,每次接口修改,这个 html 页面就会发生相应的改变,从而保证了接口文档的正确性。通过该 html 页面,可以很方便、清楚的知道这个接口的功能,并测试。

3、SpringBoot 整合 Swagger?

(1)Step1:

导入依赖 jar 包。

io.springfox

springfox-swagger2

2.9.2

io.springfox

springfox-swagger-ui

2.9.2

(2)Step2:

配置 swagger 插件。

编写一个配置类,实现 WebMvcConfigurer 接口(可以不实现该接口),用于配置 Swagger 相关信息。

@EnableSwagger2 用于开启 Swagger。

packagecom.lyh.test.test_mybatis_plus.config;importio.swagger.annotations.ApiOperation;importorg.springframework.context.annotation.Bean;importorg.springframework.context.annotation.Configuration;importorg.springframework.web.servlet.config.annotation.WebMvcConfigurer;importspringfox.documentation.builders.ApiInfoBuilder;importspringfox.documentation.builders.PathSelectors;importspringfox.documentation.builders.RequestHandlerSelectors;importspringfox.documentation.service.ApiInfo;importspringfox.documentation.spi.DocumentationType;importspringfox.documentation.spring.web.plugins.Docket;importspringfox.documentation.swagger2.annotations.EnableSwagger2;

@Configuration

@EnableSwagger2public class SwaggerConfig implementsWebMvcConfigurer {

@BeanpublicDocket createRestApi() {return newDocket(DocumentationType.SWAGGER_2)

.apiInfo(apiInfo())

.select()//加了ApiOperation注解的类,才会生成接口文档

.apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class))//指定包下的类,才生成接口文档

.apis(RequestHandlerSelectors.basePackage("com.lyh.test.test_mybatis_plus.controller"))

.paths(PathSelectors.any())

.build();

}privateApiInfo apiInfo() {return newApiInfoBuilder()

.title("Swagger 测试")

.description("Swagger 测试文档")

.termsOfServiceUrl("https://www.cnblogs.com/l-y-h/")

.version("1.0.0")

.build();

}

}<

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
回答: Swagger插件是一种用于增强Swagger文档和调试页面的工具。你可以使用swagger-ui插件来改善默认的Swagger文档和调试页面的使用体验。你可以通过添加依赖来使用该插件,具体的依赖代码如下所示: ```xml <dependency> <groupId>com.github.xiaoymin</groupId> <artifactId>swagger-bootstrap-ui</artifactId> <version>1.9.6</version> </dependency> ``` 在重启SpringBoot应用之后,你可以通过访问http://localhost:8080/doc.html来查看改进后的Swagger文档和调试页面。\[1\] 对于前端开发者来说,使用Swagger插件可以方便地找到后台接口,减少了联调的困难。这个插件可以帮助你快速定位和调试接口。\[2\] 当你点击按钮时,可以通过判断当前页面的URL是否包含"swagger-ui"来确定是否是Swagger页面。如果是Swagger页面,你可以执行相应的操作。否则,你可以给出相应的提示信息。\[3\] #### 引用[.reference_title] - *1* [Spring Boot 中使用 Swagger](https://blog.csdn.net/Huangjiazhen711/article/details/127713067)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control,239^v3^insert_chatgpt"}} ] [.reference_item] - *2* *3* [快速查找swagger接口的插件](https://blog.csdn.net/weixin_41897680/article/details/127405253)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值