优点
api文档与api定义同步更新。
直接运行在线测试api接口。
springboot 集成 swagger
- pom导入
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
</dependency>
-
配置swagger
@Configuration
@EnableSwagger2 //开启swagger
public class SwaggerConfig{
// docket 用于配置扫描的包,接口等
@Bean
public Docket docket(){
return new Docket()......
}//配置作者的信息
public ApiInfo apiInfo(){
return new ApiInfo()......
}
} -
注解
@Api
@ApiModel
@ApiModelProperty
@ApiOperation
@ApiResponse
@ApiResponses
@ApiIgnore
@Profile
@ApiImplicitParams
@ApiImplicitParam
启动项目,访问:http://localhost:8080/swagger-ui.html (8080为项目对应端口)