一、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 {@Beanpublic 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:{host}:host:{port}/api-docs.html
例如: http://localhost:7001/api-docs.html
四、说明:
为了生成漂亮的api文档,有没有采用swagger2本身的生成文档ui,而是参考了实现左右菜单式:
效果图:
1.https://github.com/caspar-chen/swagger-ui-layer
2.https://github.com/ohcomeyes/swagger-ui-layer (最终用了这个,它在上面一个进行的界面修改定制)