1.引入依赖
官方文档地址:
/**
* swagger 配置类
*/
@Configuration
@ComponentScan(basePackages = "com.imooc.swagger")
@EnableSwagger2
public class SwaggerConfiguration {
@Autowired
private SwaggerInfo swaggerInfo;
@Bean
public Docket controllerApi() {
Docket docket = new Docket(DocumentationType.SWAGGER_2)
.groupName(swaggerInfo.getGroupName())
.apiInfo(apiInfo());
ApiSelectorBuilder builder = docket.select();
if (!StringUtils.isEmpty(swaggerInfo.getBasePackage())) {
builder = builder.apis(RequestHandlerSelectors.basePackage(swaggerInfo.getBasePackage()));
}
if (!StringUtils.isEmpty(swaggerInfo.getAntPath())) {
builder = builder.paths(PathSelectors.ant(swaggerInfo.getAntPath()));
}
return builder.build();
}
private ApiInfo apiInfo() {
return new ApiInfoBuilder()
.title(swaggerInfo.getTitle())
.description(swaggerInfo.getDescription())
.termsOfServiceUrl("http://springfox.io")
.contact("imooc")
.license(swaggerInfo.getLicense())
.licenseUrl("https://github.com/springfox/springfox/blob/master/LICENSE")
.version("2.0")
.build();
}
}
说明:
需要使用分组时,只需要将 注入多个Docket即可显示多个分组
使用@ApiModelProperty在对应的接口的对象里面的字段上即可描述该字段的作用
更多使用请参考官方文档
网友评论