SpringBoot添加Swagger
添加依赖
< dependency>
< groupId> io.springfox</ groupId>
< artifactId> springfox-swagger-ui</ artifactId>
< version> 2.9.2</ version>
</ dependency>
< dependency>
< groupId> io.springfox</ groupId>
< artifactId> springfox-swagger2</ artifactId>
< version> 2.9.2</ version>
</ dependency>
添加配置类
@Configuration
@EnableSwagger2
public class SwaggerConfig {
private ApiInfo getApiInfo ( ) {
return new ApiInfoBuilder ( )
. title ( "文档标题" )
. description ( "文档详情描述" )
. version ( "1.0.1" )
. build ( ) ;
}
@Bean
public Docket getDocket ( ) {
return new Docket ( DocumentationType. SWAGGER_2)
. apiInfo ( getApiInfo ( ) )
. select ( )
. apis ( RequestHandlerSelectors. withMethodAnnotation ( ApiOperation. class ) )
. paths ( PathSelectors. any ( ) )
. build ( ) ;
}
}
应用
@RestController
@Api ( tags = "测试控制器" )
public class TestAction {
@GetMapping ( "index" )
@ApiOperation ( "测试方法" )
public Result index ( ) {
return Result. successWithMsg ( "请求成功" ) ;
}
}