インタフェース仕様闊歩

1.私たちはなぜ必要なのです

  • インタフェース記述によってテストインタフェースにインタフェーステスター - ブラックボックス
  • インターフェイスの説明を経由してインターフェースのフロントエンドの開発者を使用します。

2.書き込みインタフェースドキュメントのドキュメント

  • 直接すべてのインターフェイスを整理各アクセスアドレス(アクセス方式)、パラメータと戻り値を有します。
  • 生成された闊歩文書を読むことができますバックエンドのコード生成開発者やテスターに​​よって直接受信を行うことができるかもしれ

3.達成するために

  • 必要に応じて導入したjarパッケージ闊歩
<!-- swagger引入包-->
	<properties>
        <!--swagger对应的版本-->
        <springfox.version>2.4.0</springfox.version>
    </properties>
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger2</artifactId>
            <version>${springfox.version}</version>
        </dependency>
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger-ui</artifactId>
            <version>${springfox.version}</version>
        </dependency>
  • 書き込みSwaggerConfigクラス
package cn.wxy.crm.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
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;

//springboot  Configuration 相当于写一个applicationContext.xml
@Configuration
@EnableWebMvc  //开关配置 开启webmvc
@EnableSwagger2 //开启swagger配置
@ComponentScan(basePackages= "cn.wxy.crm.web.controller") //扫描controller
public class SwaggerConfig {

    //相当于 <bean id="api" class=""Docket/>
    @Bean
    public Docket api(){
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(this.apiInfo())
                .select()
                .apis(RequestHandlerSelectors.basePackage("cn.wxy.crm.web.controller"))
                .paths(PathSelectors.any())
                .build();
    }
    
    //生成内容 接口的信息
    private ApiInfo apiInfo(){
         @SuppressWarnings("deprecation")
         ApiInfo info=new ApiInfo(
                 "crm的接口文档",
                 "王哈哈",
                 "1.0",
                 "www.wxy.cn",
                 "王哈哈",
                 "1",
                 "www.wxy.cn");
         return info;
    }
}
  • スキャン闊歩パッケージファイルのApplicationContext-mvc.xml
<!-- 把swagger交给spring-->
    <context:component-scan base-package="cn.wxy.crm.config"></context:component-scan>

4.ファイル名を指定して実行

http://localhost/swagger-ui.html

5.結果を示します

ここに画像を挿入説明

公開された33元の記事 ウォンの賞賛0 ビュー417

おすすめ

転載: blog.csdn.net/weixin_45737653/article/details/104502179