zoukankan      html  css  js  c++  java
  • spring boot 中Swagger的使用

    在开发过程中方便测试
    1、依赖的包:
    <dependency>
    <groupId>io.springfox</groupId>
    <artifactId>springfox-swagger2</artifactId>
    <version>2.6.1</version>
    </dependency>
    <dependency>
    <groupId>io.springfox</groupId>
    <artifactId>springfox-swagger-ui</artifactId>
    <version>2.6.1</version>
    </dependency>
    <dependency>
    <groupId>io.springfox</groupId>
    <artifactId>springfox-spring-web</artifactId>
    <version>2.6.1</version>
    </dependency>

    2、配置类:
    @Configuration
    @EnableSwagger2
    public class SwaggerConfig {
    
        @Bean
        public Docket customDocket() {
            return new Docket(DocumentationType.SWAGGER_2).groupName("situation")
                    .genericModelSubstitutes(DeferredResult.class).useDefaultResponseMessages(false).forCodeGeneration(true)
                    .select().apis(RequestHandlerSelectors.basePackage("com.huawei.situation.controller"))// 选择哪些路径和API会生成document
                    .paths(PathSelectors.any())// 对所有路径进行监控
                    .build().apiInfo(apiInfo());
        }
    
        private ApiInfo apiInfo() {
            return new ApiInfoBuilder()
                    .title("Situation API")
                    .description("TCB_Site_Situation Rest API with Swagger")
                    .termsOfServiceUrl("/Situation/")
                    .contact(new Contact("xxxxxx", "", ""))
                    .license("TCB_Site_Situation License")
                    .licenseUrl("")
                    .version("1.0")
                    .build();
        }
    }

    3、在controller类上使用@Api定义controller的基本信息,在相关api接口上使用@ApiOperation、@ApiResponses来设置方法的一些基本信息、响应类型等信息
    4、localhost:port/swagger-ui.html访问页面!
  • 相关阅读:
    最近要看的项目
    Lavarel Route::resource
    架构,性能
    Unity ToLua & LuaFramework_UGUI学习笔记(zz)
    Unity UI 布局
    Introduction to Unity UI
    Unity more efficient find
    unity UI如何开启(显示)或者关闭(隐藏)Panel界面最好?
    Unity Canvas vs Panel
    Unity实现新手引导圆形遮罩
  • 原文地址:https://www.cnblogs.com/xiaoxionganna/p/9935692.html
Copyright © 2011-2022 走看看