SpringBoot集成Swagger-Bootstrap-UI

Swagger简介

  • Swagger 是一个规范且完整的框架,用于生成、描述、调用和可视化 RESTful 风格的 Web 服务。
  • Swagger 的目标是对 REST API 定义一个标准且和语言无关的接口,可以让人和计算机拥有无须访问源码、文档或网络流量监测就可以发现和理解服务的能力。当通过 Swagger 进行正确定义,用户可以理解远程服务并使用最少实现逻辑与远程服务进行交互。与为底层编程所实现的接口类似,Swagger 消除了调用服务时可能会有的猜测。
  • swagger-bootstrap-ui是基于swagger-ui做了一些优化拓展!

该开源项目GitHub地址:点击这里
该开源项目中文文档地址:点击这里

swagger-ui的界面

swagger-ui的界面

swagger-bootstrap-ui界面

swagger-bootstrap-ui
swagger-bootstrap-ui
swagger-bootstrap-ui
相比于原生的swagger-ui,swagger-bootstarp-ui提供了更好的ui界面,以及入参,出参直观的分层;
下面将swagge-bootstrap-ui整合到springboot项目中:

1.导包pom.xml

<!--swagger相关依赖-->
        <!--原生swagger-ui-->
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger2</artifactId>
            <version>2.9.2</version>
        </dependency>
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger-ui</artifactId>
            <version>2.9.2</version>
        </dependency>
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>spri
  • 3
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 4
    评论
Spring Boot项目中集成Swagger UI非常简单。以下是一些基本的步骤: 1. 添加Swagger依赖:在项目的`pom.xml`文件中添加Swagger的相关依赖。可以使用以下依赖: ```xml <dependency> <groupId>io.springfox</groupId> <artifactId>springfox-boot-starter</artifactId> <version>3.0.0</version> </dependency> ``` 2. 创建Swagger配置类:创建一个Java类,用于配置Swagger。可以使用以下示例代码: ```java 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; @Configuration @EnableSwagger2 public class SwaggerConfig { @Bean public Docket apiDocket() { return new Docket(DocumentationType.SWAGGER_2) .select() .apis(RequestHandlerSelectors.basePackage("com.example.controller")) .paths(PathSelectors.any()) .build() .apiInfo(apiInfo()); } private ApiInfo apiInfo() { return new ApiInfoBuilder() .title("API Documentation") .description("API Documentation for My Awesome App") .version("1.0.0") .build(); } } ``` 在上述代码中,`@EnableSwagger2`注解启用Swagger,`@Bean`注解创建一个`Docket`实例,配置Swagger的基本信息和扫描的包路径。 3. 启动应用程序:运行Spring Boot应用程序,Swagger UI将在`http://localhost:8080/swagger-ui.html`上自动启动。 现在,您可以在Swagger UI中浏览和测试您的API。Swagger UI将根据您的代码和注释生成API文档,并提供一个交互式的界面,供用户查看和测试API的各个端点和参数。 请注意,上述示例代码中的包路径和其他配置可能需要根据您的项目结构进行调整。此外,还可以通过其他配置选项来自定义Swagger UI的行为和外观。更多详细信息,请参阅SwaggerSpringfox的官方文档。
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值