第九节:SpringBoot 在线文档 Swagger2 入门
Swagger2 是一个开源项目,用于为 RESTful Web 服务生成 REST API 文档。它提供了一个用户界面,可以通过 Web 浏览器访问我们的 RESTful Web 服务,测试接口。
SpringBoot 集成 Swagger2 3.0 以下版本
pom.xml
Swagger2Config
配置文件
3.0 以下开启
@EnableSwagger2
这个注解
浏览器访问
http://127.0.0.1:8080/swagger-ui.html

SpringBoot 集成 Swagger2 3.0 以版本
Swagger2 3.0 版本使用更加简单
pom.xml
Swagger2Config
配置问价相差不大。
3.0 以上版本不需要
@EnableSwagger2
这个注解
启动类添加注解
注意添加
@EnableOpenApi
注解
浏览器访问
http://127.0.0.1:8080/swagger-ui/

Swagger2 常用注解
@Api
@Api 用在类上,用于说明类功能的说明

@ApiOperation

@ApiImplicitParams,@ApiImplicitParam
入参数说明
@ApiImplicitParam
其它参数

@ApiResponses
明请求返回的状态码及描述

@ApiModel
描述实体类

@ApiModelProperty
描述实体类的属性

演示案例
RumenzController
在线测试接口可以点击
Try it out
填入相关参数测试。
本小结源码地址:
GitHub:https://github.com/mifunc/springboot/tree/main/lession8
Gitee:https://gitee.com/rumenz/springboot/tree/master/lession8
https://rumenz.com/rumenbiji/springboot-swagger20-rumen.html
介绍
我的博客 https://rumenz.com/ ,
我的工具箱 https://tooltt.com/
微信公众号:【入门小站】

关注【入门小站】回复【1001】获取 linux 常用命令速查手册
关注【入门小站】回复【1003】获取 LeetCode 题解【java 语言实现】
关注【入门小站】回复【1004】获取 Java 基础核心总结
关注【入门小站】回复【1009】获取 阿里巴巴 Java 开发手册
版权声明: 本文为 InfoQ 作者【入门小站】的原创文章。
原文链接:【http://xie.infoq.cn/article/e66d413e1cb510873854f9b50】。文章转载请联系作者。
评论