zoukankan      html  css  js  c++  java
  • springboot+swagger生成api文档

    在pom文件添加依赖

    <dependency>
    <groupId>io.springfox</groupId>
    <artifactId>springfox-swagger2</artifactId>
    <version>2.7.0</version>
    </dependency>
    <dependency>
    <groupId>io.springfox</groupId>
    <artifactId>springfox-swagger-ui</artifactId>
    <version>2.7.0</version>
    </dependency>

    在启动类同目录下创建类Swagger2

    package com.medicalpay.platform;

    import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
    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
    @ConditionalOnExpression("${swagger.enable}") //开启访问接口文档的权限
    public class Swagger2 {

    @Bean
    public Docket userRestApi() {
    return new Docket(DocumentationType.SWAGGER_2)
    .groupName("结算平台") //模块名称
    .apiInfo(apiInfo())
    .select()
    .apis(RequestHandlerSelectors.basePackage("com.medicalpay.platform.v1.admin.rest")) //扫描的控制器路径
    .paths(PathSelectors.any())
    .build();
    }
    private ApiInfo apiInfo() {
    return new ApiInfoBuilder()
    .title("结算平台开发接口文档") //接口文档标题
    .description("此文档仅供开发人员,测试人员使用") //描述
    .termsOfServiceUrl("") //相关的网址
    .contact("") //作者 邮箱等
    .version("") //版本号
    .build();
    }
    }

    在配置文件配置

    swagger.enable =true

    在控制层

    类注解:@Api(tags = "接口类描述")

    方法注解:

    @ApiOperation(value = "接口作用",notes = "方法描述",response = String.class)

    启动项目后访问http://localhost:端口/swagger-ui.html

  • 相关阅读:
    201621123058《java程序设计》第八周学习总结
    201621123058《java程序设计》第七周学习总结
    201621123058《java程序设计》第六周学习总结
    201621123058《java程序设计》第五周学习总结
    关于HTK工具下载安装的问题
    load 和 loads的区别
    flask 数据库操作
    flask 计数器
    flask form表单
    flask 宏,继承和包含
  • 原文地址:https://www.cnblogs.com/you-hun/p/12486538.html
Copyright © 2011-2022 走看看