• springboot集成swagger


    1.首先引入jar包

    <dependency>
    <groupId>io.springfox</groupId>
    <artifactId>springfox-swagger2</artifactId>
    <version>2.9.2</version>
    </dependency>
    <dependency>
    <groupId>com.github.xiaoymin</groupId>
    <artifactId>swagger-bootstrap-ui</artifactId>
    <version>1.9.2</version>
    </dependency>
    2.添加swagger配置类
    package com.xxxx.xxx.client.config;

    import springfox.documentation.service.Contact;
    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;

    /**
    * @author zhangshiyu@xxx.com
    * @version 1.0
    * @date 2020/5/28 16:56
    */
    @Configuration
    @EnableSwagger2
    public class SwaggerConfig {
    @Bean
    public Docket createRestApi() {
    return new Docket(DocumentationType.SWAGGER_2)
    .apiInfo(apiInfo())
    .select()
    //为当前包路径
    .apis(RequestHandlerSelectors.basePackage("com.xxxx"))
    .paths(PathSelectors.any())
    .build();
    // return new Docket(DocumentationType.SWAGGER_2).select().apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class)).build();
    }
    //构建 api文档的详细信息函数,注意这里的注解引用的是哪个
    private ApiInfo apiInfo() {
    return new ApiInfoBuilder()
    //页面标题
    .title("xxxxSwaggerAPI")
    //创建人
    .contact(new Contact("xxxx", "", ""))
    //版本号
    .version("1.0")
    //描述
    .description("API xxxxx")
    .build();
    }
    }
    3.在controller上增加注解
    @Api(description = "xxxx接口",tag = "xxx")  controller类上 描述会展示在页面上
    public class IQuestionManagerController {


    @ApiOperation(value = "描述", notes = "说明")
    @ApiImplicitParam(name = "questionDto",value = "问题idDto",paramType = "body",required = true, dataType = "QuestionDto")
    方法上
    public QuestionDto getQuestionByQuestionId(@RequestBody QuestionDto questionDto){
    @Configuration
    @EnableSwagger2 配置类上

    访问 http://localhost:8080/doc.html就ok啦


      
    talk is cheap. show me the code.
  • 相关阅读:
    Bootstrap 4/3 页面基础模板 与 兼容旧版本浏览器
    Asp.net core 项目实战 新闻网站+后台 源码、设计原理 、视频教程
    C# 数据类型转换 显式转型、隐式转型、强制转型
    C# 多维数组 交错数组的区别,即 [ , ] 与 [ ][ ]的区别
    C#/Entity Frame Core 使用Linq 进行分页 .Skip() .Take() 的使用方法
    利用 Xunsearch 搭建搜索引擎、内容搜索实战
    Delphi
    Python
    Python
    Python
  • 原文地址:https://www.cnblogs.com/yushizhang/p/12986282.html
Copyright © 2020-2023  润新知