zoukankan      html  css  js  c++  java
  • 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.
  • 相关阅读:
    oracle执行.sql文件
    rematch的基本用法
    dva的基本用法
    redux-saga基本用法
    react-redux的基本用法
    redux的基本概念
    mobx基本概念
    centos 编译安装Apache 2.4
    javascript动态添加一组input
    php配置文件语法
  • 原文地址:https://www.cnblogs.com/yushizhang/p/12986282.html
Copyright © 2011-2022 走看看