欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

在Spring Boot中使用swagger-bootstrap-ui的方法

程序员文章站 2023-11-12 14:41:28
swagger-bootstrap-ui 是基于swagger接口api实现的一套ui,因swagger原生ui是上下结构的,在浏览接口时不是很清晰,所以, swagger...

swagger-bootstrap-ui 是基于swagger接口api实现的一套ui,因swagger原生ui是上下结构的,在浏览接口时不是很清晰,所以, swagger-bootstrap-ui 是基于左右菜单风格的方式,适用与我们在开发后台系统左右结构这种风格类似,方便与接口浏览

github: https://github.com/xiaoymin/swagger-bootstrap-ui

界面预览:

在Spring Boot中使用swagger-bootstrap-ui的方法 

引入swagger

在pom.xml文件中引入swagger以及ui的jar包依赖

<dependency>
 <groupid>io.springfox</groupid>
 <artifactid>springfox-swagger2</artifactid>
 <version>2.7.0</version>
</dependency>
<!--引入ui包-->
<dependency>
 <groupid>com.github.xiaoymin</groupid>
 <artifactid>swagger-bootstrap-ui</artifactid>
 <version>1.7</version>
</dependency>

配置configuration

配置swagger的启用配置文件,关键注解 @enableswagger2

一下配置是支持接口分组的配置,如果没有分组配置,只需要创建一个 docket 即可

@configuration
@enableswagger2
public class swaggerconfiguration {
​
 @bean
 public docket createrestapi() {
  return new docket(documentationtype.swagger_2)
    .apiinfo(apiinfo())
    .groupname("资源管理")
    .select()
    .apis(requesthandlerselectors.basepackage("com.lishiots.dc.baseinfo.ctl"))
    .paths(pathselectors.any())
    .build();
 }
 @bean
 public docket createmonitorrestapi() {
  return new docket(documentationtype.swagger_2)
    .apiinfo(apiinfo())
    .groupname("实时监测")
    .select()
    .apis(requesthandlerselectors.basepackage("com.lishiots.dc.monitor.ctl"))
    .paths(pathselectors.any())
    .build();
 }
 @bean
 public docket createactivitirestapi() {
  return new docket(documentationtype.swagger_2)
    .apiinfo(apiinfo())
    .groupname("工作流引擎")
    .select()
    .apis(requesthandlerselectors.basepackage("com.lishiots.dc.activiti.ctl"))
    .paths(pathselectors.any())
    .build();
 }
​
 @bean
 public docket createbaserestapi() {
  return new docket(documentationtype.swagger_2)
    .apiinfo(apiinfo())
    .groupname("kernel模块")
    .select()
    .apis(requesthandlerselectors.basepackage("com.lishiots.dc.kernel.ctl"))
    .paths(pathselectors.any())
    .build();
 }
​
 @bean
 public docket createcomplaintrestapi() {
  return new docket(documentationtype.swagger_2)
    .apiinfo(apiinfo())
    .groupname("投诉管理")
    .select()
    .apis(requesthandlerselectors.basepackage("com.lishiots.dc.complaint.ctl"))
    .paths(pathselectors.any())
    .build();
 }
​
 private apiinfo apiinfo() {
  return new apiinfobuilder()
    .title("swagger restful apis")
    .description("swagger restful apis")
    .termsofserviceurl("http://www.test.com/")
    .contact("xiaoymin@foxmail.com")
    .version("1.0")
    .build();
 }
}

controller层使用swagger注解

ctl代码层:​

@api(tags = "banner管理")
@restcontroller
@requestmapping("/api/bannerinfo")
public class bannerctl {
 @autowired
 private bannerinfoservice service;
 @postmapping("/query")
 @apioperation(value = "查询banner",notes = "查询banner")
 public pagination<bannerinfo> bannerinfoquery(){
  pagination<bannerinfo> pagination = service.bannerinfoquery();
  return pagination;
 }
}

接口访问

在浏览器输入:

总结

以上所述是小编给大家介绍的在spring boot中使用swagger-bootstrap-ui的方法,希望对大家有所帮助