swagger
导入依赖
创建配置文件Swagger2Config
@Configuration
@EnableSwagger2
public class Swagger2Config {
@Bean
public Docket adminApiConfig(){
return new Docket(DocumentationType.SWAGGER_2);
}
swagger常用注解
实体类级别
类的总称呼 ,描述关于
@ApiModel(value="IntegralGrade对象", description="积分等级表")
属性的称呼
@ApiModelProperty(value = "编号")
exmple 设置默认值
@ApiModelProperty(value = "更新时间",example = "1111-10-01 10:10:00")
controller
设置总接口名称
@Api(tags="积分等级管理")
接口的注释
@ApiOperation("积分等级列表")
参数的注释
@ApiParam(value = "id",required = true,example = "100")
分组设置
-
@Configuration @EnableSwagger2 public class Swagger2Config { @Bean public Docket adminApiConfig(){ return new Docket(DocumentationType.SWAGGER_2) .groupName("admin"); } @Bean public Docket webApiConfig(){ return new Docket(DocumentationType.SWAGGER_2) .groupName("web"); } }
给分组加上过滤器
-
@Bean public Docket adminApiConfig(){ return new Docket(DocumentationType.SWAGGER_2) .groupName("admin") .select()//启动一个过滤器 .paths(Predicates.and(PathSelectors.regex("/admin/.*")))//选择路径的断言,and后接上正则访问路径是/admin/的所有 .build(); }
给分组加上文档
-
public Docket adminApiConfig(){ return new Docket(DocumentationType.SWAGGER_2) .groupName("admin") .apiInfo(adminInfo()) .select()//启动一个过滤器 .paths(Predicates.and(PathSelectors.regex("/admin/.*")))//选择路径的断言,and后接上正则访问路径是/admin/的所有 .build(); } private ApiInfo adminInfo(){ return new ApiInfoBuilder() .title("后台接口文档") .description("各个接口的信息") .contact(new Contact("old cookies","www.winter.com","995794390@qq.com")) .build(); }