博主很懒...

Swagger官网:http://swagger.io

GitHub地址:https://github.com/swagger-api

官方注解文档:http://docs.swagger.io/swagger-core/apidocs/index.html

Swagger-UI地址:https://github.com/swagger-api/swagger-ui

swagger最终效果图

好,开始说Spring怎么配置Swagger了

1.pom.xml引入需要的jar包

<!-- 构建Restful API 我这版本是2.6.1 -->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>${swagger2.version}</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>${swagger2.version}</version>
</dependency>

2.扫描你的Swagger2config.java所在的包

<!-- url是你需要扫描swagger的包路径 -->
<context:component-scan base-package="com.nickwilde.microtrain.common.config.swagger"/>

3.Swagger2config.java[类名自定义]

package com.nickwilde.microtrain.common.config.swagger2;

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.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2; /**
* @author NickWilde
* @version 2018/1/18 10:23
* @description: Swagger2Config
* TODO 用一句话描述
*/
@Configuration
@EnableSwagger2
public class Swagger2Config{
@Bean
public Docket api() {
return new Docket(DocumentationType.SWAGGER_2).forCodeGeneration(true)
.select()
.apis(RequestHandlerSelectors.any())
//过滤生成链接
.paths(PathSelectors.any())
.build()
.apiInfo(apiInfo());
} //api接口作者相关信息
private ApiInfo apiInfo() {
Contact contact = new Contact("NickWilde", "", "1064698801@qq.com");
ApiInfo apiInfo = new ApiInfoBuilder()
.license("Apache License Version 2.0")
.title("Unexpectedly系统")
.description("接口文档")
.contact(contact)
.version("1.0")
.build();
return apiInfo;
}
}

4.给你的controller加上额外注解(不加也是有的)

@ApiOperation(value="根据User对象创建用户", notes="根据User对象创建用户",httpMethod = "POST") //httpMehtod如果不定义,那么swagger会有把该接口的所有请求方法都一一列举出来
@ApiImplicitParam(name = "data", value = "data描述", required = true, dataType = "UserInfo") //参数定义..类型..之类的,这是基础简单,其余的看api吧~

最新文章

  1. iOS-开发进阶
  2. Walle - 瓦力上线部署系统搭建攻略
  3. ubuntu安装py27 spyder
  4. Javascript优化后的加减乘除(解决js浮点数计算bug)
  5. 网上搜集了点资料,学web的人互相分享共同进步吧(php编码的好习惯必须养成)
  6. 论MySQL的监控和调优
  7. 多线程调用WebClient速度变慢的问题
  8. File类和RandomAccessFile类
  9. 黄聪:使用WORDPRESS自带AJAX方法
  10. DataTable导入到Excel文件
  11. JS事件监听 JS:attachEvent和addEventListener 使用方法
  12. C++ template随笔
  13. 【机器学习算法-python实现】Adaboost的实现(1)-单层决策树(decision stump)
  14. Google Earth数据存储、管理、表现及开发机制
  15. Mongodb 监测
  16. leetCode没那么难啦 in Java (二)
  17. js 操作本地sqlite
  18. ios dispatch_async使用
  19. Permanent Space 和 Heap Space
  20. IIS7 开发与 管理 编程 之 Microsoft.Web.Administration

热门文章

  1. 用烂点子打破沉默的&quot;麦当劳理论&quot;
  2. Go 在 TiDB 的实践
  3. python 多进程和子进程1
  4. How to Be Assertive Asking for What You Want Firmly and Fairly
  5. Python实例---爬取下载喜马拉雅音频文件
  6. Go语言学习笔记(六)net &amp; net/http
  7. It was not possible to find any compatible framework version
  8. November 01st, 2017 Week 44th Wednesday
  9. 2019 wannafly winter camp
  10. Phoenix安装配置