整合Springboot
依赖
https://mvnrepository.com/artifact/io.springfox/springfox-swagger2/2.9.2
<!-- swagger -->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.9.2</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.9.2</version>
</dependency>
配置
- 默认地址http://localhost:8080/swagger-ui.html
@Configuration
@EnableSwagger2
public class SwaggerConfig {
static final String VERSION = "1.0.0";
@Bean
public Docket createRestApi() {
return new Docket(DocumentationType.SWAGGER_2)
.apiInfo(apiInfo())
.select()
.apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class))
.paths(PathSelectors.any())
.build();
}
private ApiInfo apiInfo() {
return new ApiInfoBuilder()
.title("Restful APIs")
.description("restful api doc")
.version(VERSION).build();
}
}
应用
@ApiOperation(value = "测试接口", notes = "接口说明")
@ApiImplicitParams(
@ApiImplicitParam(name = "index", value = "测试参数", paramType = "query", dataType = "String")
)
@RequestMapping("/list")
public Object list(String index) {
return deviceService.list();
}