springBoot swagger Configuration配置
@Configuration
public class SwaggerConfigure {
@Bean
public Docket createRestApi() {
return new Docket(DocumentationType.SWAGGER_2)
.apiInfo(apiInfo())
.select()
.apis(RequestHandlerSelectors.basePackage("com.yspay.insurance.online.controller")) //指向你的controller包
.paths(PathSelectors.any())
.build();
}
private ApiInfo apiInfo() {
return new ApiInfoBuilder()
.title("测试系统")//这个会在Swagger页面中显示,
.description("服务")
.termsOfServiceUrl("http://localhost:7000/insurance")
.version("2.0")
.build();
}
}
maven -
<!-- 接口说明文档 -->
<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>
类 级别注解:
@Api
属性:tags-类的说明,description-覆盖类名
@ApiIgnore 隐藏接口,方法,参数
方法级别注解
@ApiImplicitParams({@ApiImplicitParam(name = "<参数名称>", value = "参数说明", required = true, paramType="body")})
paramType 值:
header-->放在请求头。请求参数的获取:@RequestHeader(代码中接收注解)
query-->用于get请求的参数拼接。请求参数的获取:@RequestParam(代码中接收注解)
path(用于restful接口)-->请求参数的获取:@PathVariable(代码中接收注解)
body-->放在请求体。请求参数的获取:@RequestBody(代码中接收注解)
form(不常用)
@ApiOperation(value = "创建订单") 方法说明
@ApiParam(value="参数说明",name="参数名",对应方法参数)
实体类注解
第一步,在实体类中@ApiModel(description= “描述”)
第二步,在字段属性中@ApiModelProperty(value = “字段备注”)