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. P1004 奶牛与牧场

    题目描述 有一个牧场,牧场上的牧草每天都在匀速生长,这片牧场可供 \(a\) 头牛吃 \(b\) 天,或可供 \(c\) 头牛吃 \(d\) 天,那么,这片牧场每天新生的草量最多可供几头牛吃1天? 输 ...

  2. testng+ant+jenkins持续集成UI自动化

    一.环境搭建 1. 安装testNG插件到eclipse. -) 选择菜单 Help /Software updates / Find and Install. -) 点击add button然后在l ...

  3. SPOJ Another Longest Increasing Subsequence Problem 三维最长链

    SPOJ Another Longest Increasing Subsequence Problem 传送门:https://www.spoj.com/problems/LIS2/en/ 题意: 给 ...

  4. Codeforces 293E 点分治+cdq

    Codeforces 293E 传送门:https://codeforces.com/contest/293/problem/E 题意: 给你一颗边权一开始为0的树,然后给你n-1次操作,每次给边加上 ...

  5. Build 2017(简体中文视频)

    视频汇总地址 入口 可筛选某天的视频 部分包含中文字幕 我看过的视频 Day1 #MSBuild Day 1 Keynote(中文字幕) Three Runtimes, one standard… . ...

  6. POJ 1166 The Clocks [BFS] [位运算]

    1.题意:有一组3*3的只有时针的挂钟阵列,每个时钟只有0,3,6,9三种状态:对时针阵列有9种操作,每种操作只对特点的几个时钟拨一次针,即将时针顺时针波动90度,现在试求从初试状态到阵列全部指向0的 ...

  7. QP简介

    QP简介 QP(Quantum Platform)是一个轻量级的.开源的.基于状态机的.事件驱动型应用程序框架.这个框架包括四部分: 事件处理器(QEP): 轻量级的事件驱动框架(QF): 任务调度微 ...

  8. xshell连接不上ubuntu---could not connect to 'ip' (port 22): Connection failed.

    可能是没有开启ssh server,接下来就是开启服务就好.命令如下: sudo apt-get install openssh-server 这样就OK啦

  9. $vjudge-$基本算法专题题解

    考完期末又双叒回来刷普及题辣$kk$ 然后放个链接趴还是$QwQ$ [X]$A$ 因为是嘤文($bushi$所以放个题意趴$QwQ$ 就汉诺塔问题,只是说有四个塔$A,B,C,D$,要求输出有1-12 ...

  10. Codeforces Round #604 (Div. 2) E. Beautiful Mirrors 题解 组合数学

    题目链接:https://codeforces.com/contest/1265/problem/E 题目大意: 有 \(n\) 个步骤,第 \(i\) 个步骤成功的概率是 \(P_i\) ,每一步只 ...