Swagger的配置安装

发布于:2022-11-05 ⋅ 阅读:(344) ⋅ 点赞:(0)

啥是swagger  

使用swagger的好处是啥

Swagger 是一个规范和完整的框架,用于生成、描述、调用和可视化 RESTful 风格的 Web 服务。总体目 标是使客户端和文件系统作为服务器以同样的速度来更新。文件的方法,参数和模型紧密集成到服务器端 的代码,允许API来始终保持同步。Swagger 让部署管理和使用功能强大的API从未如此简单。

使用依赖

<!--swagger-->
<!-- https://mvnrepository.com/artifact/io.springfox/springfox-swagger2 -->
<dependency>
    <groupId>io.springfox</groupId>
    <artifactId>springfox-swagger2</artifactId>
    <version>${swagger.version}</version>
</dependency>

@Configuration @EnableSwagger2

@Configuration @EnableSwagger2 public class SwaggerConfig { //配置文档属性 private ApiInfo getApiInfo(){ return new ApiInfoBuilder().title("商品微服务接口文档") .description("给前端妹子看的") .version("1.0") .termsOfServiceUrl("http://www.ujiuye.com") .build(); } //创建文档配置对象 @Bean public Docket docket(){ return new Docket(DocumentationType.SWAGGER_2).apiInfo(getApiInfo()) .groupName("group1") .select() .build(); }

总结步骤:

                        1:  引入swagger依赖

                        2: 创建配置类   完成swagger2的相关描述和配置   并且在类上开启swagger的注解

                        3:在代码中使用swagger注解完成类方法参数的描述

                        4:使用网址开始访问    格式http:ip+端口  swagger-ui,html