一.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();
}
}