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的信息。
    
  • 相关阅读:
    Linux-命令-seq
    怎样打开U盘最安全
    SQL Anywhere .NET
    技巧:低版本VS打开高版本VS创建的工程
    数据库插入数据返回当前主键ID值方法
    Nvelocity模板引擎
    .ashx文件与.ashx.cs
    该站点安全证书的吊销信息不可用。是否继续?
    IE8“开发人员工具”(下)
    IE8“开发人员工具”(上)
  • 原文地址:https://www.cnblogs.com/feiqiangsheng/p/12764393.html
Copyright © 2011-2022 走看看