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的信息。
    
  • 相关阅读:
    面向对象的三个特征:封装(抽象)、继承、多态
    java中流程控制有4种循环,各自的适用场景
    break 和 continue
    基础知识点总结及示例
    Java程序的运行过程,以及Java为什么能够跨平台
    JDK,JRE,JVM的区别与联系?
    jsp(二)
    JSP
    过滤器
    Servlet监听器(二)
  • 原文地址:https://www.cnblogs.com/feiqiangsheng/p/12764393.html
Copyright © 2011-2022 走看看