1.创建类
@Configuration
@EnableSwagger2
public class SwaggerConfig {
@Bean
public Docket createRestApi(){
return new Docket(DocumentationType.SWAGGER_2).apiInfo(apiInfo()).select().apis(RequestHandlerSelectors.basePackage("com.jsu.ww.controller")).paths(PathSelectors.any()).build();
//指定构建api文档的详细信息方法:apiInfo()
}
/**
* 构建api文档的详细信息
* @return
*/
private ApiInfo apiInfo(){
return new ApiInfoBuilder()
//设置页面标题
.title("Spring Boot集成Swagger2接口总览")
//设置接口描述
.description("第一个swagger接口测试")
//设置联系方式
.contact("2824768523@qq.com")
//设置版本
.version("1.0")
//构建
.build();
}
}
访问网址:http://localhost:8080/swagger-ui.html
每个接口可测试如下:
每个方法有五种测试方法,可以通过postman测试