添加swagger依赖
<!-- RESTful APIs swagger2 -->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.9.2</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.9.2</version>
</dependency>
添加配置文件
@Configuration
@EnableSwagger2
public class Swagger2Configuration {
//版本
public static final String VERSION = "1.0.0";
/**
* 门户api,接口前缀:portal
*
* @return
*/
@Bean
public Docket portalApi() {
return new Docket(DocumentationType.SWAGGER_2)
.apiInfo(portalApiInfo())
.select()
.apis(RequestHandlerSelectors.basePackage("net.sunofbeach.blog.controller.portal"))
.paths(PathSelectors.any()) // 可以根据url路径设置哪些请求加入文档,忽略哪些请求
.build()
.groupName("前端门户");
}
private ApiInfo portalApiInfo() {
return new ApiInfoBuilder()
.title("阳光沙滩博客系统门户接口文档") //设置文档的标题
.description("门户接口文档") // 设置文档的描述
.version(VERSION) // 设置文档的版本信息-> 1.0.0 Version information
.build();
}
/**
* 管理中心api,接口前缀:admin
*
* @return
*/
@Bean
public Docket adminApi() {
return new Docket(DocumentationType.SWAGGER_2)
.apiInfo(adminApiInfo())
.select()
.apis(RequestHandlerSelectors.basePackage("net.sunofbeach.blog.controller.admin"))
.paths(PathSelectors.any()) // 可以根据url路径设置哪些请求加入文档,忽略哪些请求
.build()
.groupName("管理中心");
}
private ApiInfo adminApiInfo() {
return new ApiInfoBuilder()
.title("阳光沙滩管理中心接口文档") //设置文档的标题
.description("管理中心接口") // 设置文档的描述
.version(VERSION) // 设置文档的版本信息-> 1.0.0 Version information
.build();
}
@Bean
public Docket UserApi() {
return new Docket(DocumentationType.SWAGGER_2)
.apiInfo(userApiInfo())
.select()
.apis(RequestHandlerSelectors.basePackage("net.sunofbeach.blog.controller.user"))
.paths(PathSelectors.any()) // 可以根据url路径设置哪些请求加入文档,忽略哪些请求
.build()
.groupName("用户中心");
}
private ApiInfo userApiInfo() {
return new ApiInfoBuilder()
.title("阳光沙滩博客系统用户接口") //设置文档的标题
.description("用户接口的接口") // 设置文档的描述
.version(VERSION) // 设置文档的版本信息-> 1.0.0 Version information
.build();
}
}
访问地址
localhost:端口号/swagger-ui.html