zoukankan      html  css  js  c++  java
  • Swagger basics (one)

    Swagger Introduction

    Simplify API development for users, teams, and enterprises with the Swagger open source and professional toolset. Find out how Swagger can help you design and document your APIs at scale.

    Spring Integrated Swagger

    导入依赖

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

    配置类

    @Configuration
    @EnableSwagger2
    @EnableWebMvc
    public class SwaggerConfig {
        @Bean
        public Docket api() {
            return new Docket(DocumentationType.SWAGGER_2).select().apis(RequestHandlerSelectors.any()).build()
                .apiInfo(apiInfo());
        }
    
        private ApiInfo apiInfo() {
            return new ApiInfoBuilder().title("助记宝项目接口文档")
            		.description("助记宝项目接口测试,所有的主键都不需要传(牵扯到ID的字段),创建时间也不传")
            		.version("1.0.0")
            		.build();
        }
    }
    

    配置springmvc.xml

    #开放拦截器
    <mvc:interceptors>
        <mvc:interceptor>
            <mvc:exclude-mapping path="/swagger*/**"></mvc:exclude-mapping>
        </mvc:interceptor>
    </mvc:interceptors>
    
    #开放资源
    <mvc:resources mapping="/swagger-ui.html  location="classpath:/META-INF/resources/" />
    

    常见注解

    @Api注解,用于类,表示标识这个类是swagger的资源 
    
    @ApiOperation注解,用于方法上,说明方法的作用。
    
    @ApiParam注解,用于方法参数,对方法参数进行了说明。
    
    @ApiIgnore注解,用于类、参数、方法上,注解后将不在SwaggerUI中显示。
    
    @ApiImplicitParam注解,用于对参数说明。
    
    @ApiImplicitParams注解,用于方法,包含多个@ApiImplicitParam。
    
    @ApiResponse注解,用于响应配置。
    
    @ApiModel注解,用于实体类,描述一个Model的信息。
    
  • 相关阅读:
    JavaScript访问ab页面定时跳转代码
    http协议相关-待续
    curl发送get和post请求
    Java入门——动态网页jsp(jdk下载和配置环境变量)
    LeetCode:Best Time to Buy and Sell Stock
    LeetCode:Reverse Integer
    LeetCode:Same Tree
    LeetCode:Single Number II
    LeetCode:Single Number
    LeetCode:Minimum Depth of Binary Tree
  • 原文地址:https://www.cnblogs.com/feiqiangsheng/p/12764393.html
Copyright © 2011-2022 走看看