使用の闊歩-UIのシンプルさ

威張っ-UIは、使用するのは簡単です

1. UI-闊歩何が
闊歩
対話できるの可視化APIリソースと(あなたがチームとエンドユーザーであるかどうか)SWAGGER UIは、任意の実装ロジックなしで、誰でもできます。それは、(旧闊歩として知られている)あなたのOpenAPIを自動的に視覚的な文書化、実装、および簡素化するバックエンドクライアントで生成された仕様に基づいています。

どのプロジェクトで見てみましょう
ここで使用するには、春のブートで
輸入依存度の達人

 <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.1.3.RELEASE</version>
        <relativePath/>
    </parent>

    <properties>
        <spring-cloud.version>Greenwich.RELEASE</spring-cloud.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-dependencies</artifactId>
            <version>${spring-cloud.version}</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger2</artifactId>
            <version>2.8.0</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger-ui</artifactId>
            <version>2.8.0</version>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <version>2.1.3.RELEASE</version>
            </plugin>
        </plugins>
    </build>

プログラムのポート番号を割り当てます。

server:
  port: 38682

設立スターター

package com.cs.swagger;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class SwaggerApplication {
    public static void main(String[] args) {
        SpringApplication.run(SwaggerApplication.class,args);
    }
}

インターフェースクラスのドキュメント生成を確立

package com.cs.swagger.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
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;

@Configuration
@EnableSwagger2
public class SwaggerConfig {

    @Bean
    public Docket api(){
        return new Docket(DocumentationType.SWAGGER_12)
        		// 当前的ip 和 端口号  为那个服务产生 接口文档
                .host("127.0.0.1:38682") 
                .apiInfo(apiInfo())
                .select()
                //指定对应的接口类
                .apis(RequestHandlerSelectors.basePackage("com.cs.swagger.controller"))  
                .paths(PathSelectors.any())
                .build();
    }

	//接口文档的信息
    private ApiInfo apiInfo(){
        return new ApiInfoBuilder()
                //标题
                .title("我的API文档")
                //描述
                .description("我的测试接口文档")
                //版本号
                .version("1.0")
                .build();
    }
}

対応コントローラ

package com.cs.swagger.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;


@RestController
@Api(value = "@Api 修饰整个类,描述Controller的作用")
public class SwaggerController {
    @GetMapping("/hello/{name}")
    @ApiOperation(value = "描述一个类的方法,或者说是一个接口")
    public String hello(
            @ApiParam(value = "单个参数的描述",example = "举一个例子")@PathVariable(value = "name") String name){
        return "hello" + name;
    }

}

スタートクラスはその上で直接実行するように構成されている
し、我々訪問のhttp:// localhostを:38682 /闊歩 -ui.html インタフェースのドキュメントへのアクセス
ここに画像を挿入説明ここに画像を挿入説明私たちの前に設定の詳細を取りました

 @Api:修饰整个类,描述Controller的作用
 @ApiOperation:描述一个类的一个方法,或者说一个接口
 @ApiParam:单个参数描述
 @ApiModel:用对象来接收参数
 @ApiProperty:用对象接收参数时,描述对象的一个字段
 @ApiResponse:HTTP响应其中1个描述
 @ApiResponses:HTTP响应整体描述
 @ApiIgnore:使用该注解忽略这个API
 @ApiError :发生错误返回的信息
 @ApiImplicitParam:一个请求参数
 @ApiImplicitParams:多个请求参数
公開された69元の記事 ウォンの賞賛6 ビュー2514

おすすめ

転載: blog.csdn.net/qq_40539437/article/details/103845234