pom
第一个官方 访问地址 http://localhost:你项目端口号/swagger-ui.html
第二个第三方功能跟强大 http://localhost:你项目端口号/doc.html
<!--swagger ui-->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
</dependency>
<!--第三方-->
<dependency>
<groupId>com.github.xiaoymin</groupId>
<artifactId>swagger-bootstrap-ui</artifactId>
<version>1.9.2</version>
</dependency>
添加配置类
@Configuration
@EnableSwagger2
public class Swagger2Config {
@Bean
public Docket adminApiConfig() {
return new Docket(DocumentationType.SWAGGER_2)
.groupName("adminApi")
.apiInfo(adminInfo())
.select()
.paths(Predicates.and(PathSelectors.regex("/admin/.*")))//过滤路径
.build();
}
private ApiInfo adminInfo(){
return new ApiInfoBuilder().title("金融宝后台管理API文档")
.description("本文档描述了金融宝后台管理系统接口")
.version("1.0")
.contact(new Contact("作者","","邮箱"))
.build();
}
@Bean
public Docket webApiConfig() {
return new Docket(DocumentationType.SWAGGER_2)
.groupName("webApi")
.apiInfo(webInfo())
.select()
.paths(Predicates.and(PathSelectors.regex("/api/.*")))
.build();
}
private ApiInfo webInfo(){
return new ApiInfoBuilder().title("金融宝网站后台管理API文档")
.description("本文档描述了金融宝网站后台管理系统接口")
.version("1.0")
.contact(new Contact("作者","","邮箱"))
.build();
}
}