swagger2:(一)spring boot整合swagger2(生成有左右菜单式的api文档界面)

一、pom.xml内容:

<!--=====依赖swagger2 zhongzk 2019.7.7 -->
<dependency>
   <groupId>io.springfox</groupId>
   <artifactId>springfox-swagger2</artifactId>
   <version>2.9.2</version>
</dependency>
<dependency>
   <groupId>com.github.ohcomeyes</groupId>
   <artifactId>swagger-ui-layer</artifactId>
   <version>1.2</version>
</dependency>

二、SwaggerConfig.java

package com.zjm.gwork.utils;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.context.request.async.DeferredResult;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * @ClassName: SwaggerConfig
 * @Description: SwaggerConfig 配置类
 * 1.
 * 2.
 * @Author: zhongzk 28582157@qq.com
 * @Date: 2019/7/7 13:33 *
 * @Copyright: 2018 字节码团队www.bjsurong.com. All rights reserved.  *
 */
@Configuration
@EnableSwagger2
public class SwaggerConfig {
    @Bean
    public Docket ProductApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .genericModelSubstitutes(DeferredResult.class)
                .useDefaultResponseMessages(false)
                .forCodeGeneration(false)
                .pathMapping("/")
                .select()
                .build()
                .apiInfo(productApiInfo());
    }

    private ApiInfo productApiInfo() {
        ApiInfo apiInfo = new ApiInfo("GWORK系统数据接口文档",
                "文档描述。。。",
                "1.0.0",
                "API TERMS URL",
                "联系人邮箱:18618281321@163.com",
                "license",
                "license url");
        return apiInfo;
    }
}

三、访问:swagger-ui-layer 的默认访问地址是 http://${host}:${port}/api-docs.html

例如:  http://localhost:7001/api-docs.html

四、说明:

为了生成漂亮的api文档,有没有采用swagger2本身的生成文档ui,而是参考了实现左右菜单式:

效果图:

api-info

1.https://github.com/caspar-chen/swagger-ui-layer

2.https://github.com/ohcomeyes/swagger-ui-layer (最终用了这个,它在上面一个进行的界面修改定制)

 

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值