-
介绍:swagger-bootstrap-ui 1.9.1 发布了。swagger-bootstrap-ui是 Swagger 的增强UI 实现,使文档更友好一点儿,同时可以提供离线的md文档。码云链接
-
使用说明:
Maven中引入Jar包
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.9.2</version>
</dependency>
然后引入SwaggerBootstrapUi的jar包
<dependency>
<groupId>com.github.xiaoymin</groupId>
<artifactId>swagger-bootstrap-ui</artifactId>
<version>1.9.1</version>
</dependency>
编写Swagger2Config配置文件
Swagger2Config配置文件如下:
@Configuration
@EnableSwagger2
public class SwaggerConfiguration {
@Bean
public Docket createRestApi() {
return new Docket(DocumentationType.SWAGGER_2)
.apiInfo(apiInfo())
.select()
//此处为controller包路径
.apis(RequestHandlerSelectors.basePackage("com.bycdao.cloud"))
.paths(PathSelectors.any())
.build();
}
private ApiInfo apiInfo() {
return new ApiInfoBuilder()
.title("swagger-bootstrap-ui RESTful APIs")
.description("swagger-bootstrap-ui")
.termsOfServiceUrl("http://localhost:8999/")
.contact("developer@mail.com")
.version("1.0")
.build();
}
}
controller配置:
需要再controller头上添加
@Api(value = "xxx", description = "xxxxxxxxxxxx")
/**
* 默认推荐和学科推荐
* @param type
* @param page
* @param size
* @return
*/
//此注解对接口的说明
@ApiOperation("默认推荐和学科推荐")
//此注解为对字段的说明,可以加可以不加
@ApiImplicitParam(name = "type", value = "资源分类字段(csdb,website)", dataType = "String")
@ResponseBody
@GetMapping("/recommend")
public SdbResult recommend(@RequestParam(name = "type", required = false) String type,
@RequestParam(name = "page", defaultValue = "1") int page,
@RequestParam(name = "size", defaultValue = "10") int size){
return queryAccessService.recommend(type, page, size);
}
在启动类上配置
@SpringBootApplication
//添加此注解
@EnableSwagger2
public class IrpResourcepoolApplication{
public static void main(String[] args) {
SpringApplication.run(IrpResourcepoolApplication.class, args);
}
}
访问地址:
swagger-bootstrap-ui默认访问地址是:http://${host}:${port}/doc.html
UI效果图