赞
踩
swagger-bootstrap-ui是基于swagger接口api实现的一套UI,因swagger原生ui是上下结构的,在浏览接口时不是很清晰,所以,swagger-bootstrap-ui是基于左右菜单风格的方式,适用与我们在开发后台系统左右结构这种风格类似,方便与接口浏览
1.访问地址的不同
官方:http://localhost:8763/swagger-ui.html#/
bootstrap-ui访问地址: http://localhost:8080/doc.html#/
2.界面展示不同
官方: 竖向展示参数
bootstrap-ui: 是横向展示参数
3.启动类添加注解的不同
官方: 需要添加@EnableSwagger2
bootstrap-ui: 不需要添加@EnableSwagger2
通过swagger-bootstrap-ui 下载源码.解压-
可以查看到doc.html 从而得知访问路径
1.swagger依赖
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.9.2</version>
</dependency>
2…swagger-bootstrap-ui的依赖
<dependency>
<groupId>com.github.xiaoymin</groupId>
<artifactId>swagger-bootstrap-ui</artifactId>
<version>1.9.6</version>
</dependency>
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import springfox.documentation.builders.ApiInfoBuilder; import springfox.documentation.builders.PathSelectors; import springfox.documentation.builders.RequestHandlerSelectors; import springfox.documentation.service.ApiInfo; import springfox.documentation.spi.DocumentationType; import springfox.documentation.spring.web.plugins.Docket; import springfox.documentation.swagger2.annotations.EnableSwagger2; /** * @ClassName: SwaggerConfig * @version: 1.0 * @description: swagger-config类 * @create: 2020-08-06 14:34 * * 通过@Configuration注解,让Spring来加载该类配置。 * * 通过@EnableSwagger2注解来启用Swagger2。 **/ @Configuration @EnableSwagger2 public class SwaggerConfig { @Bean public Docket createRestApi() { return new Docket(DocumentationType.SWAGGER_2) .apiInfo(apiInfo()) .select() // 要扫描的API(Controller)基础包 .apis(RequestHandlerSelectors.basePackage("com.ion.web.controller")) // 要扫描的API(Controller)全局-(就是可以扫描所有的带有api注解的包并生成文档) // .apis(RequestHandlerSelectors.any()) .paths(PathSelectors.any()) .build(); } //配置在线文档的基本信息 private ApiInfo apiInfo() { return new ApiInfoBuilder() .title("springboot利用swagger构建api文档") .description("简单优雅的restfun风格,https://me.csdn.net/blog/miachen520") .termsOfServiceUrl("https://me.csdn.net/blog/miachen520") .version("1.0") .build(); } }
如果觉得界面不喜欢 可以添加如何依赖 美化swagger的界面
1.使用knife4j的引用配置-(美化swagger界面)
<dependency>
<groupId>com.github.xiaoymin</groupId>
<artifactId>knife4j-spring-boot-starter</artifactId>
<!--在引用时请在maven中央仓库搜索最新版本号-->
<version>2.0.4</version>
</dependency>
@EnableKnife4j
@Import(BeanValidatorPluginsConfiguration.class)
http://localhost:8080/doc.html#/home
排除静态文件
registry.addResourceHandler("swagger-ui.html")
.addResourceLocations("classpath:/META-INF/resources/");
registry.addResourceHandler("doc.html").addResourceLocations("classpath:/META-INF/resources/");
registry.addResourceHandler("/webjars/**")
.addResourceLocations("classpath:/META-INF/resources/webjars/");
赞
踩
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。