pom.xml
<!-- https://mvnrepository.com/artifact/io.springfox/springfox-swagger2 -->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.9.2</version>
</dependency>
<!-- https://mvnrepository.com/artifact/io.springfox/springfox-swagger-ui -->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.9.2</version>
</dependency>
引入依赖后,在Application这个类上使用注解@EnableSwagger2即可
启动项目,访问localhost:8080/swagger-ui.html
swagger注释@API详细说明
swagger是当前最好用的Restful API文档生成的开源项目,通过swagger-spring项目实现了springMVC框架的无缝集成功能,方便生成restful风格的接口文档,同时,swagger-ui还可以测试spring restful风格的接口功能
作用范围 API 使用位置
对象属性 @ApiModelProperty 用在参数对象的字段上
协议集描述 @Api 用在Conntroller类上
协议描述 @ApiOperation 用在controller方法上
Response集 @ApiResponses 用在controller方法上
Response @ApiResponse 用在@ApiResponses里面
非对象参数集 @ApilmplicitParams 用在controller方法上
非对象参数描述 | @ApiImplicitParam | 用在@ApiImplicitParams的方法里边 |
描述返回对象的意义 | @ApiModel | 用在返回对象类上 |
@Api value - 字段说明 description - 注释说明这个类
//在controller的方法上
@ApiOperation(value = "方法说明",notes = "注释说明")
@ApiImplicitParams({
@ApiImplicitParam(name = "参数名", value = "参数注释", required = true, paramType = "query", dataType = "String")
})