- 引入依赖
- 配置
- 常用注解
- entity
- controller上
- 接口分组配置
- 修改文档页面描述信息
配置io.springfox springfox-swagger2 ${swagger.version} io.springfox springfox-swagger-ui ${swagger.version}
@Configuration
@EnableSwagger2
public class SwaggerConfig {
@Bean
public Docket apiConfig() {
return new Docket(documentationType.SWAGGER_2);
}
}
常用注解
entity
- 类上, 用来描述这个类
@ApiModel(value="IntegralGrade对象", description="积分等级表")
- 属性上, 用来描述字段
@ApiModelProperty(value = "编号")controller上
- 类上用来描述接口
@Api(tags = "积分等级管理")
- 方法上, 用来描述方法
// notes是进一步说明 @ApiOperation(value = "积分等级列表", notes = "查询所有未删除的数据")
- 参数上, 用来描述参数
public boolean remove(@ApiParam(value = "数据id", example = "100") Long id)接口分组配置
修改配置
@Configuration
@EnableSwagger2
public class SwaggerConfig {
@Bean
public Docket adminApiConfig() {
return new Docket(documentationType.SWAGGER_2)
.groupName("后端管理接口")
.select() // 创建过滤器
.paths(s -> s.matches("/admin/.*"))
.build();
}
@Bean
public Docket webApiConfig() {
return new Docket(documentationType.SWAGGER_2)
.groupName("前端管理接口")
.select() // 创建过滤器
.paths(s -> s.matches("/api/.*"))
.build();
}
}
修改文档页面描述信息
修改配置类
@Configuration
@EnableSwagger2
public class SwaggerConfig {
@Bean
public Docket adminApiConfig() {
return new Docket(documentationType.SWAGGER_2)
.groupName("后端管理接口")
.apiInfo(getAdminApiInfo())
.select() // 创建过滤器
.paths(s -> s.matches("/admin/.*"))
.build();
}
private ApiInfo getAdminApiInfo() {
return new ApiInfoBuilder()
.title("xxx后端管理API文档")
.description("文档描述了xxx后端管理接口调用方式")
.version("1.6")
.contact(new Contact("mine", "xxx@163.com", "http://www.mine.com"))
.build();
}
@Bean
public Docket webApiConfig() {
return new Docket(documentationType.SWAGGER_2)
.groupName("前端管理接口")
.apiInfo(getWebApiInfo())
.select() // 创建过滤器
.paths(s -> s.matches("/api/.*"))
.build();
}
private ApiInfo getWebApiInfo() {
return new ApiInfoBuilder()
.title("xxx客户端管理API文档")
.description("文档描述了xxx客户端端管理接口调用方式")
.version("1.6")
.contact(new Contact("mine", "xxx@163.com", "http://www.mine.com"))
.build();
}
}



