使用swagger通过简单的配置可以生成简单的接口文档;

依赖包:

// Swagger2
compile 'io.springfox:springfox-swagger2:2.8.0'
compile 'io.springfox:springfox-swagger-ui:2.8.0'

启动类添加配置:

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication
@EnableAutoConfiguration
public class ShowCaseApplication { public static void main(String[] args) {
SpringApplication.run(ShowCaseApplication.class, args);
}
}

配置类:

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
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.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2; @Configuration
@ComponentScan(basePackages = { //"com.a.controller", //
})
@EnableSwagger2
public class AutoConfiguration { @Bean
public Docket docketCommon() {
return new Docket(DocumentationType.SWAGGER_2)
.groupName("test").select()
.apis(RequestHandlerSelectors.basePackage("com.a.controller"))
.paths(PathSelectors.any())
.build()
.apiInfo(new ApiInfoBuilder().
title("test Restful API").
description("接口API").
contact(new Contact("", "", "")).
version("1.0").
build());
}
}

接口注释:在controller里的接口上面添加标识

	@ApiOperation(nickname = "getList", value = "获取列表。")
@Override
public List<String> getList(
@RequestBody @ApiParam(name = "请求对象", value = "传入json格式", required = true) TestRequest request) {
return null
}

  

使用Swagger生成简单接口文档的更多相关文章

  1. spring boot使用swagger生成api接口文档

    前言 在之前的文章中,使用mybatis-plus生成了对应的包,在此基础上,我们针对项目的api接口,添加swagger配置和注解,生成swagger接口文档 具体可以查看本站spring boot ...

  2. .NET Core WEB API使用Swagger生成在线接口文档

    1项目引用Swashbuckle.AspNetCore程序集和Microsoft.Extensions.PlatformAbstractions程序集 右击项目打开"管理NuGet程序包.. ...

  3. swagger 生成的接口文档,隐藏接口的某个参数

    [问题描述] controller 中的处理请求的方法,有时候会添加一些额外的参数.比如下面代码中 UserVo: @PostMapping(value = "/add-office-par ...

  4. .netcore Swagger 生成 api接口文档

    1, 引用第三方包, Swashbuckle.AspNetCore Swashbuckle.AspNetCore.Swagger Swashbuckle.AspNetCore.SwaggerUI 最简 ...

  5. Swagger+Spring mvc生成Restful接口文档

    简介 Swagger 是一个规范和完整的框架,用于生成.描述.调用和可视化 RESTful 风格的 Web 服务.总体目标是使客户端和文件系统作为服务器以同样的速度来更新.文件的方法,参数和模型紧密集 ...

  6. Spring Boot 集成 Swagger 生成 RESTful API 文档

    原文链接: Spring Boot 集成 Swagger 生成 RESTful API 文档 简介 Swagger 官网是这么描述它的:The Best APIs are Built with Swa ...

  7. Spring MVC学习总结(9)——Spring MVC整合swagger自动生成api接口文档

    Swagger 号称:世界最流行的API框架,官网:http://swagger.io/,Swagger 是一个规范和完整的框架,用于生成.描述.调用和可视化 RESTful 风格的 Web 服务.总 ...

  8. Swagger: 一个restful接口文档在线生成+功能测试软件

    一.什么是 Swagger? Swagger 是一款RESTFUL接口的文档在线自动生成+功能测试功能软件.Swagger 是一个规范和完整的框架,用于生成.描述.调用和可视化 RESTful 风格的 ...

  9. springboot项目利用Swagger2生成在线接口文档

    Swagger简介. Swagger2是一款restful接口文档在线生成和在线调试工具.很多项目团队利用Swagger自动生成接口文档,保证接口文档和代码同步更新.在线调试.简单地说,你可以利用这个 ...

随机推荐

  1. Project2--Lucene的Ranking算法修改:BM25算法

    原文出自:http://blog.csdn.net/wbia2010lkl/article/details/6046661 1.       BM25算法 BM25是二元独立模型的扩展,其得分函数有很 ...

  2. YII 模型关联之 一对一

    需求,一个用户对应一个用户信息表,  这两者之间的关系就是一对一 //首先查找出一个用户出来 $user=Users::find()->'])->one(); //然后查询, 第一个参数是 ...

  3. HtmlHelper扩展

    扩展 HtmlHelper类 public static class MyHtmlHelper { //扩展方法 //静态类,静态方法,this关键字 //调用方法<%=Html.MyLabel ...

  4. c# 判断网络地址是否存在

    方法一:网络地址存在,有可能可以访问,也有可能不能访问.此方法用来判断地址存在. static bool UrlIsExist(String url) { System.Uri u = null; t ...

  5. DBMS ODBC JDBC是什么?

    昨天躺在被窝里面看了几页电子书,今天写下来. 数据库就是存放数据的仓库. DBMS的意思是数据库管理系统,作用就是“管理”数据库的.“管理”这两个字简单说来就是“增删改查”.所以DBMS就是能够对数据 ...

  6. Linux 编译内核

    编译内核步骤: 1.先查看自己OS使用的内核版本 mrzhang@mrzhang:~$ uname -r4.4.0-51-genericmrzhang@mrzhang:~$ 2.如果安装系统时,自动安 ...

  7. dev初识 拖动分组

    1.前台代码 <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm ...

  8. OVS的初始配置

    1.去掉bridge模块,为下面用OVS的模块奠定基础 rmmod bridge .insmod datapath/linux/openvswitch_mod.ko .insmod datapath/ ...

  9. Open Message Queue 集群问题

    nohup ./imqbrokerd -tty -name myBroker -port 7677 -javahome /opt/omae/jdk1.7.0_45 -cluster 192.168.2 ...

  10. CSS3中的新特性

    一.CSS3新属性 CSS3还不属于W3C标准,所以不同浏览器的支持程度也不相同,对于不同浏览器,写法也不同,不同内核的浏览器要加不同的前缀,如下: transform:rotate(9deg); - ...