整体的Swagger配置文件:
@Configuration
@EnableSwagger2
public class SwaggerConfig {
@Bean
public Docket docket(){
return new Docket(documentationType.SWAGGER_2)
.apiInfo(apiInfo())
.select()
// 配置要扫描的包的相对路径
.apis(RequestHandlerSelectors.basePackage("com.example.swragger_test.controller"))
// .paths(PathSelectors.ant("/example/**"))//过滤路径
.build()
.groupName("chenzou项目组")
;
}
private ApiInfo apiInfo(){
Contact contact = new Contact("checkout", "www.baidu.com", "213156465@1235.com");
return new ApiInfo("丝袜哥的学习",
"给我一瓶酒,再给我一支烟,给你给一个api文档",
"2.0",
"urn:tos",
contact,
"Apache 2.0",
"http://www.apache.org/licenses/LICENSE-2.0",
new ArrayList());
}
}
导入依赖:
io.springfox
springfox-swagger2
2.8.0
io.springfox
springfox-swagger-ui
2.8.0
编写写配置类:
@Configuration
@EnableSwagger2
public class SwaggerConfig {
}
启动springboot,访问下面链接:
http://localhost:8080/swagger-ui.html
访问到这个界面代表配置成功 swagger信息配置@Configuration
@EnableSwagger2
public class SwaggerConfig {
@Bean
public Docket docket(){
return new Docket(documentationType.SWAGGER_2)
.apiInfo(apiInfo());
}
private ApiInfo apiInfo(){
Contact contact = new Contact("checkout", "www.baidu.com", "213156465@1235.com");
return new ApiInfo("丝袜哥的学习",
"给我一瓶酒,再给我一支烟,给你给一个api文档",
"2.0",
"urn:tos",
contact,
"Apache 2.0",
"http://www.apache.org/licenses/LICENSE-2.0",
new ArrayList());
}
}
swagger配置扫描接口
@Bean
public Docket docket(){
return new Docket(documentationType.SWAGGER_2)
.apiInfo(apiInfo())
.select()
// 配置要扫描的包的相对路径
.apis(RequestHandlerSelectors.basePackage("com.example.swragger_test.controller"))
// .paths(PathSelectors.ant("/example/**"))//过滤路径
.build()
;
}
一些注释配置:
分为不同的项目组:
请求参数:
用户实体类的注释:
HINT:swagger还有一个快速测试接口的功能:



