zoukankan      html  css  js  c++  java
  • spring boot 中使用 swagger

    1. 添加Swagger2依赖

    <dependency>
        <groupId>io.springfox</groupId>
        <artifactId>springfox-swagger2</artifactId>
        <version>2.2.2</version>
    </dependency>
    <dependency>
        <groupId>io.springfox</groupId>
        <artifactId>springfox-swagger-ui</artifactId>
        <version>2.2.2</version>
    </dependency>



    2.

    创建Swagger2配置类

    在Application.java同级创建Swagger2的配置类Swagger2。

    @Configuration
    @EnableSwagger2
    public class Swagger2 {
    
        @Bean
        public Docket createRestApi() {
            return new Docket(DocumentationType.SWAGGER_2)
                    .apiInfo(apiInfo())
                    .select()
                    .apis(RequestHandlerSelectors.basePackage("com.twsm.test"))
                    .paths(PathSelectors.any())
                    .build();
        }
    
        private ApiInfo apiInfo() {
            return new ApiInfoBuilder()
                    .title("Spring Boot中使用Swagger2构建RESTful APIs")
                    .description("测试接口")
                    .termsOfServiceUrl("www.baidu.com")
                    .contact("twsm")
                    .version("1.0")
                    .build();
        }
    
    }


    3. 添加文档内容
    我们通过@ApiOperation注解来给API增加说明、通过@ApiImplicitParams@ApiImplicitParam注解来给参数增加说明

    4. 访问 http://localhost:777/swagger-ui.html#/
  • 相关阅读:
    Java多态性理解
    多态详解
    public static void main(String[] args){}函数诠释
    继承、封装
    面向对象的理解
    重载与构造函数的解析
    冒泡排序及二分查找
    数组总结之补充
    计算机中如何表示数字-07IEEE754浮点数标准
    synchronized 和ReentrantLock
  • 原文地址:https://www.cnblogs.com/xiangjune/p/6872415.html
Copyright © 2011-2022 走看看