如今相信大部分公司都已經(jīng)實現(xiàn)前后端分離的開發(fā)模式,所以前后端溝通成為不可避免的問題,怎么更加清晰明了的進行交接蚤霞,API文檔是不可避免的,所以Swagger還是值得推薦的
雖然也不是特別的滿意,比如代碼的移入性較高沦寂,可是總體來說看起來還是比較明了的
一袁铐、配置依賴:
<!-- swagger2.0依賴 -->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.6.1</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.6.1</version>
</dependency>
二揭蜒、進行配置
代碼如下:
@Configuration
@EnableSwagger2
public class SwaggerConfig {
@Bean
public Docket buildDocket() {
return new Docket(DocumentationType.SWAGGER_2).apiInfo(buildApiInf()) // .apiInfo(apiInfo())
.select().apis(RequestHandlerSelectors.basePackage("com.yq"))// 要注釋的接口名
.paths(PathSelectors.any()).build();
}
private ApiInfo buildApiInf() {
return new ApiInfoBuilder().title("自己測試 API").termsOfServiceUrl("http://wapp.ncyunqi.com").version("1.0.0")
.build();
}
}
三、在啟動項進行配置注解@EnableSwagger2 表示開啟Swagger
四剔桨、打開訪問頁面