swagger的使用之一swagger在idea的引入


一.swagger的使用

   swagger资料查询网站:https://mvnrepository.com/

第一步:进入网站

 

 

第二步:

 

 第三步:选着版本

 

 第四步引入依赖:

 

 第五步:搜索swagger试图

 

 第六步:找到和swagger对应的版本

 

 

 

 到这依赖就找完了,接下来在idea里面使用

二.在idea中进行配置

一.首先先配置Pom.xml

<!--swagger依赖-->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.9.2</version>
</dependency>
<!--swagger的试图-->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.9.2</version>
</dependency>

 

二.创建Swagger2配置类

/*
@EnableSwagger2是springfox提供的一个注解代表swagger2相关技术开启。
会扫描当前类所在地,及子包中所有的类型中的注解。做swagger文档的定值。
*/
首先在启动类上面引入
@EnableSwagger2

Application.java同级创建Swagger2的配置类Swagger2

@Configuration
@EnableSwagger2
public class Swagger2 {

@Bean
public Docket createRestApi() {
return new Docket(DocumentationType.SWAGGER_2)
.apiInfo(apiInfo())
.select()
.apis(RequestHandlerSelectors.basePackage("com.cheshi.cheshi"))
.paths(PathSelectors.any())
.build();
}

private ApiInfo apiInfo() {
return new ApiInfoBuilder()
.title("Spring Boot中使用Swagger2构建RESTful APIs")
.description("更多Swagger相关文章请关注:https://www.cnblogs.com/yongyuankuaile/p/15337473.html")
.termsOfServiceUrl("https://www.cnblogs.com/yongyuankuaile/p/15337473.html")
.contact("KL")
.version("1.0")
.build();
}

}


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM