前言
記錄軟件開發(fā)點(diǎn)滴,積累知識和經(jīng)驗(yàn)(第一篇)
要做什么?
目標(biāo):完成springboot集成swagger的功能。
怎樣去做?
- 引入對應(yīng)的jar(pom.xml)
<!-- swagger-ui -->
<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>
- 配置swagger(swagger2Config.java)
@Configuration
@EnableSwagger2
public class Swagger2Config {
@Bean
public Docket createRestApi() {
return new Docket(DocumentationType.SWAGGER_2)
.apiInfo(apiInfo())
.select()
.apis(RequestHandlerSelectors.basePackage("com.wyl.controller"))
.paths(PathSelectors.any())
.build();
}
private ApiInfo apiInfo() {
return new ApiInfoBuilder()
.title("springboot利用swagger構(gòu)建api文檔")
.description("簡單優(yōu)雅的restfun風(fēng)格,http://blog.csdn.net/saytime")
.termsOfServiceUrl("http://blog.csdn.net/saytime")
.version("1.0")
.build();
}
}
- swagger的相關(guān)使用
@Api(用在類中標(biāo)明這個類的作用)
@ApiOperation(用在方法中,標(biāo)明這個方法的作用)
@ApiImplicitParams(用在有參數(shù)的方法中,標(biāo)明參數(shù)的作用)
結(jié)果怎么樣?
在這里插入圖
在這里插入圖