1、pom文件新增restdocs

<dependency>   
<groupId>org.springframework.restdocs</groupId>
<artifactId>spring-restdocs-mockmvc</artifactId>   
<scope>test</scope>
</dependency>
<plugin>   
<groupId>org.asciidoctor</groupId>
<artifactId>asciidoctor-maven-plugin</artifactId>   
<version>1.5.8</version>   
<executions>       
<execution>           
<id>generate-docs</id>           
<phase>prepare-package</phase>           
<goals>               
<goal>process-asciidoc</goal>           
</goals>           
<configuration>               
<backend>html</backend>               
<doctype>book</doctype>           
</configuration>       
</execution>   
</executions>   
<dependencies>       
<dependency>
<groupId>org.springframework.restdocs</groupId>
<artifactId>spring-restdocs-asciidoctor</artifactId>
<version>${spring-restdocs.version}</version>
</dependency>   
</dependencies>
</plugin>

2、在test包下新建controller

@RunWith(SpringRunner.class)
@SpringBootTestpublic class ApiBaseController {    @Rule   
public JUnitRestDocumentation restDocumentation = new JUnitRestDocumentation();    public MockMvc mockMvc;    @Autowired   
private WebApplicationContext context;    @Before   
public void setUp() {       
this.mockMvc = MockMvcBuilders.webAppContextSetup(this.context)
.apply(documentationConfiguration(this.restDocumentation))
.build();   
}
}

3、新建单元测试

public class TestController extends ApiBaseController {
@Test   
public void test() throws Exception {       
super.mockMvc.perform(post("/test").param("aaa", "bbb")               
.contentType(MediaType.APPLICATION_JSON))               
.andDo(document("{ClassName}/{methodName}",
preprocessRequest(prettyPrint()), preprocessResponse(prettyPrint()),                       
requestParameters(parameterWithName("aaa").description("查询名字"))));   
}
}

4、运行后会在target\generated-snippets生成adoc文件

5、在main下新建asciidoc包,新建index.adoc 拼接已经生成的adoc

= API:toc:
left:toclevels: 4
[[order-it]]
== 1. 订单接口
[[order-query]]
=== 订单查询
operation::TestController/test[snippets='curl-request,http-request']

springboot集成restdocs输出接口文档的更多相关文章

  1. SpringBoot集成Swagger2在线文档

    目录 SpringBoot集成Swagger2在线文档 前言 集成SpringBoot 登录接口文档示例 代码 效果 注解说明 总结 SpringBoot集成Swagger2在线文档 前言 不得不说, ...

  2. SpringBoot 如何生成接口文档,老鸟们都这么玩的!

    大家好,我是飘渺. SpringBoot老鸟系列的文章已经写了两篇,每篇的阅读反响都还不错,果然大家还是对SpringBoot比较感兴趣.那今天我们就带来老鸟系列的第三篇:集成Swagger接口文档以 ...

  3. springboot使用swagger2创建文档

    一.导入swagger2依赖 <dependency> <groupId>io.springfox</groupId> <artifactId>spri ...

  4. Springboot+swagger2的接口文档开发

    一.创建一个SpringBoot项目 1. 2. 3. 4. 把web里的web选中,SQL里选择自己需要的,点击next 二.创建各项所需的controller,configure等 1. 项目布局 ...

  5. SpringCloud微服务实战——搭建企业级开发框架(六):使用knife4j集成Swagger2接口文档

    knife4j是为集成Swagger生成api文档的增强解决方案,前后端Java代码以及前端Ui模块进行分离,在微服务架构下使用更加灵活, 提供专注于Swagger的增强解决方案,不同于只是改善增强前 ...

  6. Springboot swagger2 导出api文档

    具体导出的代码,参考了:http://www.spring4all.com/article/699 导出前,首先需要配置好swagger2,参见 https://www.cnblogs.com/yan ...

  7. springboot + swagger2 生成api文档

    直接贴代码: <dependency> <groupId>io.springfox</groupId> <artifactId>springfox-sw ...

  8. SpringBoot+FreeMarker开发word文档下载,预览

    背景: 开发一个根据模版,自动填充用户数据并下载word文档的功能 使用freemarker进行定义模版,然后把数据进行填充. maven依赖: <parent> <groupId& ...

  9. spring-boot+swagger实现WebApi文档

    1.引用依赖包 <dependency> <groupId>io.springfox</groupId> <artifactId>springfox-s ...

随机推荐

  1. 记前端状态管理库Akita中的一个坑

    记状态管理库Akita中的一个坑 Akita是什么 Akita是一种基于RxJS的状态管理模式,它采用Flux中的多个数据存储和Redux中的不可变更新的思想,以及流数据的概念,来创建可观察的数据存储 ...

  2. 2018-2-13-WPF-拖动时出现-Invalid-FORMATETC-structure

    title author date CreateTime categories WPF 拖动时出现 Invalid FORMATETC structure lindexi 2018-2-13 17:2 ...

  3. java IO的概述和File方法

    IO流用来处理设备之间的数据传输        Java对数据的操作是通过流的方式        Java用于操作流的对象都在IO包中 File类在整个IO包中与文件本身有关的操作类,所有的与文件本身 ...

  4. 【t091】油滴扩展

    Time Limit: 1 second Memory Limit: 128 MB [问题描述] 在一个长方形框子里,最多有N(0≤N≤6)个相异的点.在其中任何一个点上放一个很小的油滴,那么这个油滴 ...

  5. [转载]sublime用法精华

    Sublime Text 全程指南 九月 03.2015. 暂无评论 永远站 作者:Lucida 原文链接:http://lucida.me/blog/sublime-text-complete-gu ...

  6. ubuntu-wine

    sudo dpkg --add-architecture i386 sudo add-apt-repository ppa:wine/wine-buildssudo apt-get update su ...

  7. mysql find_in_set 与 in 的用法与区别,mysql范围搜索,mysql范围查询

    mysql find_in_set 与 in 的用法与区别 1.find_in_set 用于模糊查询,并且数据库中的值是用英文逗号分隔的: 例如: (1).去字段中查询 select find_in_ ...

  8. Adam Harley的卷积神经网络3D视觉化模型

    https://m.huxiu.com/article/138857/1.html 最近 Google Tensorflow 做了一个非常直观的神经网络 playground.不夸张地说,现在每个人都 ...

  9. javascript继承的几种方法

    继承是面向对象编程中很重要的概念,在其它面向对象的语言中大都很简单,例如java中有关键词extends来实现 javascript语言在ES6也新增了extends关键词可以实现继承,用法与java ...

  10. jquery中报错Uncaught ReferenceError: $ is not defined的解决办法

    jquery中报错提示为:Uncaught ReferenceError: $ is not defined 这个错误的原因就是你没有引入jquery库文件或者引入的路径不对造成的